The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-08-2009
yomaya yomaya is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 11
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!
  #2 (permalink)  
Old 06-08-2009
shubhendu shubhendu is offline
Registered User
  
 

Join Date: May 2009
Location: 12° 58' N & 77° 38' E
Posts: 29
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
will work.
  #3 (permalink)  
Old 06-08-2009
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,078
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
  #4 (permalink)  
Old 06-08-2009
yomaya yomaya is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 11
Both ideas work perfectly. As I'm only testing a couple of fast ideas by now, I'll keep the Perl code in the safe...

Thanks a lot!
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:26 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0