Hi,
I have a issue, I need to loop through a comma delimited file and check for the length which exceeds specified length , if Yes truncate the string.
But my problem is , I do not have to check for all the fields and the field lenght is not same for all the fields.
For ex:
Say my line
ahjdh,dfhkajhdf,adhklf,eiour
say I need to check length only for 2nd and 4th and max length for 2nd is 6
I am trying to trim spaces for the fixed width file starting from location 129 and of length 20.
I am expecting only around 40 records that will have length greater than 9. But i am getting around 4000 records.
Please help me correct the following.
Code:
nawk '{if (a=length(gsub(/ */,"",substr($0,129,20)))>9); print $a }' testfile |wc -l
Running below line gives 3957 as length of longest line in file 20121119_SRMNotes_init.dat
Code:
awk ' { if ( length > 3950 ) { x = length } }END{ print x }' 20121119_SRMNotes_init.dat
While wc -L 20121119_SRMNotes_init.dat gives output as 4329. Why is there a difference between these two commands.
Thanks
Hello
I'm manipulating a file, taking certain variables & printing them to an output file using awk (actually nawk because I'm using -v).
I now want to take a field from the input file & expand it to a pre-defined length by preceding the string with spaces.
I need a script that will run in unix to:
1) Read and input file with 1 column that contains for ex:
0123456789
1234567890
...etc
2) Checks the first column if it is:
a. Numeric from 0 - 9
b.
I was wondering if I could use AWK to print from the nth character position to nth for all records in the file.
All I have been doing is printing/copying fields rather than characters. I found a way to print lines greater/less/equal to a character length which led me to believe there is a way to do this in awk.
If this can't be done in awk, then how could it be done?
Thanks!
I have a log-file where at the end of a series of lines you can see if this block is relevant
now I'm looking for a command like sed to delete de blocks ending with "Content-Length: 0" and beginning with the last "--" before this line.
I tried sed -n "/--/,/Content-Length: 0/d" but this takes the first "--" and the first "Content-Length: 0" and deletes it.
ex :
line 1 "--"
line 2
line 3 "
I have a log-file where at the end of a series of lines you can see if this block is relevant
now I'm looking for a command like sed to delete de blocks ending with "Content-Length: 0" and beginning with the last "--" before this line.
I tried sed -n "/--/,/Content-Length: 0/d" but this takes the first "--" and the first "Content-Length: 0" and deletes it.
ex :
line 1 "--"
line 2
line 3 "
Hi,
The record length may be differ in afile. I want to display the records if the record length is not equal to 50 using sed/awk command.
Thanks in Advance