Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

removing a particular field from some of the lines in a filed

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 10-18-2012   -   Original Discussion by dev.devil.1983
dev.devil.1983's Unix or Linux Image
dev.devil.1983 dev.devil.1983 is offline
Registered User
 
Join Date: Oct 2012
Last Activity: 31 March 2017, 9:13 AM EDT
Posts: 39
Thanks: 17
Thanked 0 Times in 0 Posts
removing a particular field from some of the lines in a filed

Hi All,

i have a file having multiple lines but mainly constitues of following two types



Code:
1) Sat,Oct,1,01:04:51,2011,Local,ESSBASE0,Info(1051037),Logging,out,user,210073155,,,active,for,63,minutes,GETS_SAL,loaded



Code:
2) Thu,Sep,20,13:08:52,2012,Local,ESSBASE0,50,Info(1051037),Logging,out,user,hypadmin,,,active,for,0,minutes,Application,GETS_GL


need to bring all the lines in the same format by removing the field '50'(highlighted in red) from the lines containing it. this filed mainly contains 2 digit numbers and can be values other than 50.

Thanks in advance Linux
Sponsored Links
    #2  
Old Unix and Linux 10-18-2012   -   Original Discussion by dev.devil.1983
pamu's Unix or Linux Image
pamu pamu is offline
Registered User
 
Join Date: Mar 2012
Last Activity: 1 August 2017, 11:23 AM EDT
Posts: 1,650
Thanks: 58
Thanked 478 Times in 474 Posts
one simple way..Linux



Code:
sed 's/ESSBASE0\,[0-9][0-9]/ESSBASE0/g' file

Sponsored Links
    #3  
Old Unix and Linux 10-18-2012   -   Original Discussion by dev.devil.1983
itkamaraj's Unix or Linux Image
itkamaraj itkamaraj is offline Forum Advisor  
Registered User
 
Join Date: Apr 2010
Last Activity: 19 April 2018, 3:48 AM EDT
Posts: 3,148
Thanks: 45
Thanked 698 Times in 674 Posts


Code:
$ nawk -F, -v OFS=, 'NF==21{for(i=8;i<NF;i++)$i=$(i+1);NF=20}1' input.txt
Sat,Oct,1,01:04:51,2011,Local,ESSBASE0,Info(1051037),Logging,out,user,210073155,,,active,for,63,minutes,GETS_SAL,loaded
Thu,Sep,20,13:08:52,2012,Local,ESSBASE0,Info(1051037),Logging,out,user,hypadmin,,,active,for,0,minutes,Application,GETS_GL

if you dont have nawk, then try with awk
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Removing spaces in the second field alone pandeesh UNIX for Dummies Questions & Answers 8 12-23-2011 05:47 AM
Removing empty lines(space) between two lines containing strings sudhakaryadav Shell Programming and Scripting 3 06-02-2009 10:01 AM
Removing parts of a specific field kieranh Shell Programming and Scripting 9 09-28-2007 12:52 PM
removing last field of the line adddy UNIX for Dummies Questions & Answers 4 12-11-2006 10:35 PM



All times are GMT -4. The time now is 06:10 PM.