deleting particular lines using shell scripting
i ve written a program which gives the output something like this,:
Code:
C4' A A 25 P C A 26 3.909728 using sed command we can delete lines but in this case what should i do/ please help me |
Assuming the file /tmp/disco contains that output:
[dancing@jonasandneil tmp]$ cat /tmp/disco | head -9 C4' A A 25 P C A 26 3.909728 P C A 26 C4' C A 26 3.963673 P C A 26 P U A 27 6.040643 C4' C A 26 P U A 27 3.892993 P U A 27 C4' U A 27 3.962986 P U A 27 P C A 28 6.240974 C4' U A 27 P C A 28 3.907594 P C A 28 C4' C A 28 3.962415 P C A 28 P C A 29 5.776231 |
hey pls be elaborate i dint understand the solution sorry, could u pls tel me again ?
please |
oh u r cutting the lines after 9 lines, but my code gives files with different number of lines , so how do i do then ?
i mean i dono how many number of lines r there, i just know the pattern of lines. |
This one uses a regular expression to ensure the line contains a float with at least number.number
omg:~# cat testa.txt | grep "[0-9]\.[0-9]" C4' A A 25 P C A 26 3.909728 P C A 26 C4' C A 26 3.963673 P C A 26 P U A 27 6.040643 C4' C A 26 P U A 27 3.892993 P U A 27 C4' U A 27 3.962986 P U A 27 P C A 28 6.240974 C4' U A 27 P C A 28 3.907594 P C A 28 C4' C A 28 3.962415 P C A 28 P C A 29 5.776231 |
describe your criteria for deletion clearly next time. From what i can see, you just don't want lines that are less than 9 fields.
Code:
awk 'NR<9' file |
I am assuming you want to delete the lines that do not have the last column in the output.
The following script will work if the format of the rest of the columns remain the same, put the script into a file say "delete_lines" { if(NF<=8) print $0 } Assuming the data is stored in file called test_file and run the script using the command awk -f delete_lines test_file |
assuming that your program output is in the file "file". However you better pipe the output of your program to below awk; it's neater, e.g. ( #myprog | below awk )
Code:
naif@master ~/LQ> cat file You can ofcourse redirect the awk output to some other file. o btw, i used nawk, awk should work as well. |
Hey guys please help me i am not able to delete those lines using
cat testa.txt | grep "[0-9]\.[0-9]" |
You don't say if you tried any of the other solutions----or what happened when you tried the grep. (It worked for me)
Here is another method (same Regex as the grep): Code:
sed '/[0-9]\.[0-9]/!d' filename Code:
sed '/[0-9]\.[0-9]/!d' filename > newfilename |
All times are GMT -5. The time now is 05:42 PM. |