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
string editing in files Avatar Gixxer Shell Programming and Scripting 3 09-18-2008 08:17 AM
editing a file via a shell script ?? jimmyc Shell Programming and Scripting 2 03-28-2008 12:21 PM
Editing a file in a shell script jowpup UNIX for Dummies Questions & Answers 3 02-08-2005 04:45 AM
Editing a file using a script Ypnos Shell Programming and Scripting 45 07-02-2003 09:39 AM
Editing one string in multiple files Skoshi UNIX for Dummies Questions & Answers 1 11-10-2001 02:13 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-10-2008
nookie nookie is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 9
SH Script help. editing string

I have a string that looks like this

username|field1|field2|field3

the data has a delimiter of "|"
how can i edit field1, keeping the rest of the data the same
also how can i edit field2 and 3.
  #2 (permalink)  
Old 10-10-2008
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,382
edit in the sense you want to replace the first field with some other word keeping other intact??
if so use awk
Code:
echo "username|field1|field2|field3"|awk -F\| '{print "word|"$2"|"$3"|"$4}'
output will be
word|field1|field2|field3
same way you can do your second question also
  #3 (permalink)  
Old 10-10-2008
nookie nookie is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 9
> edit in the sense you want to replace the first field with some other word keeping other intact??
yup that was what i meant



that is very simple to understand.
thank you very much
  #4 (permalink)  
Old 10-10-2008
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,310

No need for any external commands:

Code:
string="username|field1|field2|field3"
newfield1=something
newstring="$newfield1|${string#*|}"
Sponsored Links
Closed Thread

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:05 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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