Home Man
Today's Posts

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.

replacing one filed at run time in UNix

shell scripts

Login to Reply

Thread Tools Search this Thread
# 1  
Old 05-08-2006
replacing one filed at run time in UNix

Hi All,
My requirement is :
My input file is :

2 , 56, 23, 43,
1 , 32 , 5, 6,
10 , 2, 3, 4,

Now i want the output as
new, 56, 23, 43,
new,32 , 5, 6,
new , 2, 3, 4,

Please help me

# 2  
Old 05-08-2006
what have you tried so far ?

try this,

awk -F"," '{ print "new,", $2,",",$3,",", $4,","}' samplefile
# 3  
Old 05-09-2006
Thanks for the prompt reply.
Actuaaly i have a file with around 115 fileds in each row.
So with your method it will work but will be clumsy to write such a big code
Any simpler code !!

Thanks a lot
# 4  
Old 05-09-2006
sed -e "s/^[^,]*\(,.*\)/new \1/g" input.txt > output.txt

# 5  
Old 05-09-2006
Hi Vino,

Can you pls explain your command as I'm trying to learn sed too and it'll be helpful for me.

# 6  
Old 05-09-2006
sed -e "s/^[^,]*\(,.*\)/new \1/g" input.txt > output.txt

[^,]* means a character-set containing all those characters which are not , (comma)
\(,.*\) is capture a string which matches the pattern , (comma) followed by anything.

Then replace the character-set with *new* followed by the pattern.

Write everything into output.txt
# 7  
Old 05-09-2006
with awk for any no. of fields

awk -F"," '$1="new"{print}' samplefile
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
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
Convert UTC time into current UNIX sever time zone mohanalakshmi Shell Programming and Scripting 5 12-11-2013 07:19 PM
Adding time to date time in UNIX shell scipting codehelp04 Shell Programming and Scripting 3 12-03-2012 04:31 AM
Converting string date time to unix time in AWK bkkid UNIX for Dummies Questions & Answers 2 08-19-2012 04:06 PM
How to get time duration between two human readable time stamp in Unix? ford99 Shell Programming and Scripting 3 07-19-2011 09:52 AM
Convert Unix Time to Standard Time mrlayance Shell Programming and Scripting 7 04-23-2009 02:19 PM
How To Provide Time Sync Using Nts-150 Time Server On Unix Network? pesty UNIX for Advanced & Expert Users 2 03-22-2007 02:20 AM
Help needed - Replacing all date & time occurrences in a file with a string using Sed Hema_M Shell Programming and Scripting 4 11-17-2005 12:42 AM

All times are GMT -4. The time now is 04:32 AM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
Show Password