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 > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to combine fields from different files littleb Shell Programming and Scripting 2 3 Weeks Ago 04:23 AM
plus values from two files differient fields. jimmy_y Shell Programming and Scripting 4 06-23-2009 04:43 AM
Merging two files by comparing three fields Hunter85 Shell Programming and Scripting 3 06-10-2009 05:18 PM
merging fields from 2 different files. rudoraj Shell Programming and Scripting 5 11-02-2008 02:59 AM
To get an output by combining fields from two different files smriti_shridhar Shell Programming and Scripting 8 10-22-2008 06:21 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 2 Weeks Ago
paoie paoie is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 5
Red face Fields in csv files using sed

Hi,

I am working right now with a csv file and I want to insert an excel formula say to the 6th column.

sample csv file:

Code:
1234,lag,0,77,544,,7
1234,lag,222,0,7,,7
at first i used a simple command:

Code:
sed 's/^\(.\{17\}\)/\1word/' file.csv
but the result is this:

Code:
1234,lag,0,77,544word,,7
1234,lag,222,0,7,word,7
result should be:

Code:
1234,lag,0,77,544,word,7
1234,lag,222,0,7,word,7
i'm a newbie in unix.

I tried using the sed command i found in one the the threads here but i can only make it work to insert up to 2 columns. I don't really understand how to this works. hope somebody could help. thanks!

this is not mine, I just found this command from one of the threads here:
Code:
sed 's/^\([^,]*\),[^,]*,/\1,word,/' file.csv
result:

Code:
1234,word,lag,0,77,544,,7
1234,word,lag,222,0,7,,7
and i cant seem to make it work so that it will insert a word in the 7th column.


Thanks!

Last edited by Franklin52; 2 Weeks Ago at 06:37 AM.. Reason: Please use code tags!
  #2 (permalink)  
Old 2 Weeks Ago
scottn scottn is online now Forum Advisor  
VIP Member
  
 

Join Date: Jun 2009
Location: Zürich, CH
Posts: 1,042
Code:
awk -F, -v OFS=, '{ $6 = "word" } 1' file1
1234,lag,0,77,544,word,7
1234,lag,222,0,7,word,7
Or if it's always field 6 and none of the earlier fields are empty:
Code:
sed "s/,,/,word,/" file1
1234,lag,0,77,544,word,7
1234,lag,222,0,7,word,7
  #3 (permalink)  
Old 2 Weeks Ago
paoie paoie is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 5
thank you very much scottn! it worked!! haha :-)
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 03:03 PM.


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