![]() |
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 |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to remove comma from the last line of the file | sandeep_1105 | UNIX for Dummies Questions & Answers | 5 | 05-27-2009 12:01 PM |
| remove unnecessary comma from file | sumeet | UNIX for Advanced & Expert Users | 1 | 12-31-2008 06:00 PM |
| is is possible remove junk chars from the strings? | balan_mca | Shell Programming and Scripting | 1 | 10-31-2008 07:26 PM |
| Remove whitespaces between comma separated fields from file | nitinbjoshi | UNIX for Dummies Questions & Answers | 2 | 06-14-2008 08:14 AM |
| Remove non printing chars | oti | Shell Programming and Scripting | 8 | 06-18-2004 11:23 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
regex to remove text before&&after comma chars
Hi, all: I have a question about "cleaning up" a huge file with regular expression(s) and sed:
The init file goes like this: block1,blah-blah-blah-blah,numseries1,numseries2,numseries3,numseries4 block2,blah-blah-blah-blah-blah,numseries,numseries2,numseries3,numseries4 ... block99999,blah-blah-blah,numseries,numseries2,numseries3,numseries4 And the final output should result as: blah-blah-blah-blah blah-blah-blah-blah-blah blah-blah-blah In short, I would need to remove in every line: 1) everything from the '^' to the first ',' before blah-blahs 2) everything from the first ',' after blah-blahs to the '$' I've tried it by using the following sed command without success: sed -e "s/^.*,//g" -e "s/,.*//g" file.in > file.out Thanks in advance! |
|
||||
|
if your input is symmetric.. i.e blah blah is always the second column then CUT should be a better option.
Please confirm if this is the case. If so, Code:
cut -d"," -f2 <input_file> > <output_file |
|
||||
|
Code:
while(<DATA>){
my @tmp=split(",",$_,3);
print $tmp[1],"\n";
}
__DATA__
block1,blah-blah-blah-blah,numseries1,numseries2,numseries3,numseries4
block2,blah-blah-blah-blah-blah,numseries,numseries2,numseries3,numseries4
block99999,blah-blah-blah,numseries,numseries2,numseries3,numseries4
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|