LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Working with Tab-Delimited files (https://www.linuxquestions.org/questions/linux-newbie-8/working-with-tab-delimited-files-450142/)

shiroh_1982 05-31-2006 01:59 AM

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..

chrism01 05-31-2006 02:59 AM

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

shiroh_1982 06-02-2006 02:47 AM

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..

timmeke 06-02-2006 02:58 AM

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


shiroh_1982 06-02-2006 03:53 AM

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

timmeke 06-02-2006 04:08 AM

\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...


All times are GMT -5. The time now is 07:33 AM.