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
Format a text file jhardy Shell Programming and Scripting 2 03-17-2009 02:32 PM
changing the format of CSV file ashis.tewari Shell Programming and Scripting 5 12-09-2008 07:38 AM
Changing display and format of file wahi80 UNIX for Dummies Questions & Answers 1 08-02-2008 08:12 PM
Conver Excel file to another format ( text) ZINGARO HP-UX 6 07-23-2008 01:52 PM
Changing the column for a row in a text file and adding another row aYankeeFan Shell Programming and Scripting 9 05-02-2005 09:42 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-11-2009
kavithakuttyk kavithakuttyk is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 16
Changing the text file format

Hi,
I have a shell script to unload all the empname who have salary >50000 from the emp table into a text file(empname.txt) .
m_db unload "$dbc_file" -column_delimiter ',' -select "SELECT empname FROM emp where salary > 50000" >> empname.txt

Now my text file have data in the following format
cat empname.txt
kkk,
abc,
efg,
hij,
lmn,
...,
etc
I want to change all these values in the below mentioned format and each string should have single codes.

cat empname.txt
'kkk','abc','efg','hij','lmn','...','...',etc

How can I change this in the shell script?.If anybody knows please help me to resolve this.
  #2 (permalink)  
Old 06-11-2009
BubbaJoe's Avatar
BubbaJoe BubbaJoe is offline
Registered User
  
 

Join Date: Oct 2008
Location: St Louis
Posts: 153
You can try this.

Code:
cat empname.txt | sed "s/^/\'/" | sed "s/,/\',/" | tr -d "\n"
  #3 (permalink)  
Old 06-11-2009
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
Quote:
Originally Posted by BubbaJoe View Post
You can try this.

Code:
cat empname.txt | sed "s/^/\'/" | sed "s/,/\',/" | tr -d "\n"
There's no need for cat; there's no need for multiple sed-s; there's no need to escape a single quote.
Code:
sed "s/[^,][^,]*/'&'/;\$s/,$//" empname.txt| tr -d '\n'
  #4 (permalink)  
Old 06-11-2009
kavithakuttyk kavithakuttyk is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 16
Thanks for all your suggestions .It works fine for me now
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 06:27 AM.


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