Home Man
Search
Today's Posts
Register

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

Tags
shell scripts

Login to Reply

 
Thread Tools Search this Thread
# 1  
Old 10-18-2012
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
# 2  
Old 10-18-2012
one simple way..

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

# 3  
Old 10-18-2012
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
Login to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
awk repeat one field at all lines and modify field repetitions phaethon Shell Programming and Scripting 2 09-19-2015 07:29 PM
Joining broken lines and removing empty lines Jackceasar123 Shell Programming and Scripting 7 11-18-2014 06:34 PM
Replacing first field of file2 with the second filed of file1 for matching cases ailnilanjan Shell Programming and Scripting 6 11-06-2014 05:14 AM
Removing PATTERN from txt without removing lines and general text formatting AxeHandle UNIX for Dummies Questions & Answers 5 09-24-2014 12:12 AM
Replace first field of a line with previous filed of the line usha rao Shell Programming and Scripting 4 08-06-2013 07:34 AM
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:20 PM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password