LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-06-2012, 03:34 AM   #1
vidimythsss
LQ Newbie
 
Registered: Sep 2012
Posts: 2

Rep: Reputation: Disabled
Smile Replacing a part of csv file with one variable value


Hi there,

I have one csv file.. ex- xyz.txt
content is like ...
123|asdsdsd|2323|sfdsdasd

I want to read this file, and then replace the first field 123, which is before the ' | ' , with one variable value, say $count , whose value is integer only .

Please help me in this !!
 
Old 09-06-2012, 04:02 AM   #2
deadeyes
Member
 
Registered: Aug 2006
Posts: 609

Rep: Reputation: 79
cat file | sed 's/^123|/newvalue|/g'

cat file | sed "s/^123|/$var|/g"
 
1 members found this post helpful.
Old 09-06-2012, 07:33 AM   #3
vidimythsss
LQ Newbie
 
Registered: Sep 2012
Posts: 2

Original Poster
Rep: Reputation: Disabled
Mate,

This was for one particular file, How can I do this for all such file pattern . Normally, there will be some 15 files, I want to have command, which can replace the first field of the given file name with the variable provided . Please help me in that .
 
Old 09-06-2012, 08:30 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,425

Rep: Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826
Did you try the examples? the only negative I have would be not to use cat as it serves no purpose being that sed can read a file or multiple files (hint).
 
Old 09-06-2012, 11:23 AM   #5
deadeyes
Member
 
Registered: Aug 2006
Posts: 609

Rep: Reputation: 79
Quote:
Originally Posted by grail View Post
Did you try the examples? the only negative I have would be not to use cat as it serves no purpose being that sed can read a file or multiple files (hint).
Totally correct I am very used to cat things and then pipe them to another program. Bad habit

I think I tackled what you asked, vidimythsss.
Or maybe the explanation is unclear.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to script csv editing? Remove rows from csv file that do not contain certain text ingram87 Linux - Software 9 08-03-2012 01:45 PM
replacing part of filename berrance Linux - Newbie 9 04-25-2010 11:10 AM
LXer: Convert SpreadSheets to CSV files with Python and pyuno, Part 2 LXer Syndicated Linux News 0 01-15-2009 04:30 AM
Comparing two csv files and write different record in third CSV file irfanb146 Linux - Newbie 3 06-30-2008 10:15 PM
Replacing part (lines) of a file ( bash or perl ) zomane Programming 3 10-26-2007 05:10 PM


All times are GMT -5. The time now is 02:06 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration