Hi i am trying to replace blank lines with a number 0. I tried the following code
awk '{print NF ? $0: blankrow}' blankrow = "0" file1.prg>file2.prg
however i get the following error: fatal: cannot open file `blankrow' for reading (No such file or directory)
file example:
1
2
3
5
6
file output>
1
2
3
0
5
0
6
- thank u
PS i have also tried using echo "file.prg" |sed's!\" "!\"0"!g' -> results with an error -seds!\" "!\"0"!g: command not found
Remove the spaces around the = sign:
awk '{print NF?$0:blankrow}' blankrow=0 file1.prg>file2.prg
tried that.. didnt work
bash: awk{print NF?$1:blankrow}blankrow=0: command not found
And why don't you just copy/paste the command above ...
I'm sure you see that the command you run is different.
lol.. thanks.. worked fine... thanks.. wonders of pasting..
had another concern
in the output file.. if i had to add another field with just tab (blank space every line) would
i just say awk '{print NF?$0:blankrow}' blankrow=0; print " "
or awk '{print NF?$0:blankrow}' blankrow=0; print $0 "\t"
output file example:
1 (tab)
2 (tab)
0 (tab)
3 (tab)
4 (tab)
0 (tab)
awk '$0=($0?$0:0)"\t"' infile
i merged another code with the previous code u gave -
{print NF?$0:blankrow}blankrow=0{print NR $0 "\t"}
i do get the tabs.. but is it possible to make the tabs like a seperate field?
No need to merge, just use this:
awk '$0=($0?$0:0)" \t"' infile
the tabs are not alliged properly to make it a seperate field
output:
1(tab)
2(tab)
10(tab)
desired output:
1 (tab)
2 (tab)
3 (tab)
10 (tab)
Could post the output from the following command:
awk '$0=($0?$0:0)" \t"' infile|cat -te
I get this:
% awk '$0=($0?$0:0)" \t"' infile|cat -te
1 ^I$
2 ^I$
3 ^I$
0 ^I$
5 ^I$
0 ^I$
6 ^I$
digit -> space -> tab
Is this the desired result?
May be this illustrates it better:
% awk '$0=($0?$0:0)" \t"' infile|od -cbw4
0000000 1 \t \n
061 040 011 012
0000004 2 \t \n
062 040 011 012
0000010 3 \t \n
063 040 011 012
0000014 0 \t \n
060 040 011 012
0000020 5 \t \n
065 040 011 012
0000024 0 \t \n
060 040 011 012
0000030 6 \t \n
066 040 011 012
0000034
Or perhaps you want something like this?
(adjust the length if you need: -10, -15, -20 ...)
awk '$0=sprintf("%-15s",$0?$0:0)' infile