LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 05-31-2006, 01:59 AM   #1
shiroh_1982
LQ Newbie
 
Registered: May 2006
Posts: 9

Rep: Reputation: 0
Working with Tab-Delimited files


I have a tab-Delimited file:
Eg:
'test' file contains:
a<tab>b<tab>c<tab>....

Based on certain condition, I wanna increase the number of lines of this file.How do I do that
Eg:
If some value in the database is 1 then one line in 'test' file is fine..
If some value in the database is 2 then 2 lines in the 'test' file is required with the second line not matching the first line(this is req since i wanna perform a replace command later(Eg: replace 'a' with '1')

Eg:
'test' file will then contain:
a<tab>b<tab>c<tab>....
d<tab>e<tab>f<tab>....

i need to simulate this using a shell scripts..kindly help me..
 
Old 05-31-2006, 02:59 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,362

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Accessing a DB from shell is a bit fiddly, but when you've done that you can just append a line to the file each time eg
line=a<tab>b<tab>c
echo $line >>filename
 
Old 06-02-2006, 02:47 AM   #3
shiroh_1982
LQ Newbie
 
Registered: May 2006
Posts: 9

Original Poster
Rep: Reputation: 0
Thanks for ur reply Chrish, however the result i got was this:

<Empty line>
a<space>b<space>c..

Now im not sure if that space qualifies for a <tab>..do we have to convert it using tr or sumtng..lemme know..
 
Old 06-02-2006, 02:58 AM   #4
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
Try:
Code:
echo -e "a\tb\tc" >> file
Horizontal tab (\t) is often used in special way by the shell (ie filename completion) and hence may not
be translated to the proper ASCII char.
See man echo for details.

Check out also:
Code:
man ascii
man iso-8859-1
man echo
 
Old 06-02-2006, 03:53 AM   #5
shiroh_1982
LQ Newbie
 
Registered: May 2006
Posts: 9

Original Poster
Rep: Reputation: 0
Thanks timmeke..worked fine..But another question..

Suppose there is req ie:
a<Tab>b<Tab>c<Tab>d<space>e<Tab>

Then how do we go ahead with this...for tab we use \t..is there anytng for space??? i check man echo didnt find anytng

Kindly lemme know
 
Old 06-02-2006, 04:08 AM   #6
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
\s is space, but doesn't seem to work with "echo". However, you can just type spaces too. Just don't forget the double (or single) quotes.
Example:
Code:
echo -e "a\tb\tc\td e\tf"
works on my box...
 
  


Reply



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
FC 4. Modify ALT+TAB behaviour to CTRL+TAB xtracto Linux - Software 1 09-22-2005 02:06 PM
extended tab functionality not working on mandrake build oobayly Linux - General 1 04-21-2005 09:12 AM
delimited and if nstanley Linux - Newbie 11 03-01-2004 09:35 AM
Parsing a tab delimited text file jajanes Programming 9 08-08-2003 10:34 AM
*tab files. whitefox Linux - Newbie 2 04-18-2003 02:50 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:41 PM.

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
Open Source Consulting | Domain Registration