![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Need to replace the first word of a line if it occurs again in the next line(shell) | geeko | Shell Programming and Scripting | 4 | 06-18-2009 02:36 PM |
| How to Select or cut from the certain filed to the end of the line | grajesh_955 | Shell Programming and Scripting | 5 | 04-10-2008 07:07 AM |
| awk program to select a portion of a line | anju | Shell Programming and Scripting | 3 | 01-11-2008 06:33 AM |
| Select matches between line number and end of file? | Jerrad | Shell Programming and Scripting | 4 | 05-24-2006 07:50 AM |
| awk to select a column from particular line number | mab_arif16 | Shell Programming and Scripting | 4 | 05-08-2006 05:26 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
How to select line by line in shell
Hi,
This is what the file data.lst contains. aaaaaaaa eeeeeeeeeeeeeeee 4444444 rrrrrrrrrrrrr tttttttttttt bbbbbbbb eeeeeeeeeeeeeeee 7777777 uuuuuuuu eeeeeeeee qqqqqqqq gggggggggggggggg 6666666 oooooooo ppppppppp Here I want to cut the third field and put it in a new file I tried this way echo for i in `cat data.lst` do echo $i | cut -c 30-37 >> newfile.lst done But this doesn't work.Can someone help me. Thanks in advance Last edited by preethgideon; 10-11-2006 at 06:28 PM.. |
|
||||
|
Hi Andrek,
I have another problem. I have have a similar file this way aaaaaaaa eeeeeeeeeeeeeeee 4444R16 rrrrrrrrrrrrr tttttttttttt bbbbbbbb eeeeeeeeeeeeeeee 7777777 uuuuuuuu eeeeeeeee qqqqqqqq gggggggggggggggg 6666R16 oooooooo ppppppppp In some lines last 3 digits of the third field ends with R16.If it ends with R16 then concatinate to a new file else proceed. Help !! |
|
||||
|
Python alternative:
Code:
o = open("output","a")
for line in open("input.txt"):
line = line.strip().split()
if line[2].endswith("R16"):
print >>o, ' '.join(line)
o.close()
/home> python test.py aaaaaaaa eeeeeeeeeeeeeeee 4444R16 rrrrrrrrrrrrr tttttttttttt qqqqqqqq gggggggggggggggg 6666R16 oooooooo ppppppppp |
|
||||
|
Quote:
Code:
sed -n "/R16/p" file | sed -n "s/\([^0-9]*\)\([0-9]\{4\}R16\).*/\2/w filewithR16"
Code:
cut -d" " -f3 file | grep "R16" > filewithR16 Code:
awk ' $3 ~ "R16" { print $3 }' file > filewithR16
Code:
sed -n "/R16/! p" file | sed -n "s/\([^0-9]*\)\([0-9][0-9]*\).*/\2/w filewithoutR16" Code:
cut -d" " -f3 file | grep -v "R16" > filewithoutR16 Code:
awk ' $3 !~ "R16" { print $3 }' file > filewithR16
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|