Replace semicolons with tabulators, new lines are disappearing


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replace semicolons with tabulators, new lines are disappearing
# 1  
Old 01-10-2013
Bug Replace semicolons with tabulators, new lines are disappearing

Hi Gurus!
Example file:
Code:
1;AAA;BBB
2;CCC;DDD

We want to replace semicolons to tabulators.
Like this:
Code:
1    AAA    BBB
2    CCC    DDD

We have tried these codes.
With PERL:
Code:
#!/bin/bash
for i in `find /folder1/ -name "*.CSV"`

do
bi="`basename $i   awk -F"." {'print $1'}`"

cat $bi.CSV   perl -p -e 's/;/\t/g' > /folder1/$bi.TXT

mv $bi.CSV /folder2/

done

and same with SED:

Code:
#!/bin/bash
for i in `find /folder1/ -name "*.CSV"`

do
bi="`basename $i   awk -F"." {'print $1'}`"

sed 's/;/\t/g' $i > /folder1/$bi.TXT

mv $bi.CSV /folder2/

done

But when processed, all the rows are concatenated to one row, like this:
Code:
1    AAA    BBB    2    CCC    DDD

What can be wrong with the script?

Last edited by Scrutinizer; 01-10-2013 at 08:28 AM.. Reason: code tags also for data
# 2  
Old 01-10-2013
Try something like this:
Code:
awk '$1=$1' FS=";" OFS="\t" file

# 3  
Old 01-10-2013
Or
Code:
$ tr ';' '     ' <file
1    AAA    BBB
2    CCC    DDD

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Printing paragraph between semicolons having XXXX

Hello experts, I have below file: 1 2 3 4 5 6 ; 7 8 9 10 XXXX 1 ; 2 3 (4 Replies)
Discussion started by: manuswami
4 Replies

2. Shell Programming and Scripting

[Solved] Disappearing backslash

Let's say I have a text file called process.out that contains: cn=long\, ann,cn=users cn=doe\, john,cn=users I need to have the following appended in the beginning ldapdelete -h $OIDHOST So the final output looks like: ldapdelete -h $OIDHOST "cn=long\, ann,cn=users" ldapdelete -h... (4 Replies)
Discussion started by: exm
4 Replies

3. UNIX for Dummies Questions & Answers

Problems removing files with semicolons in the filename

There are some 40 files created by accident with filenames with semicolons, as well as other non-printable characters. I can not find a correct way to delete them. This is what I tried: bash-2.03# ls bad|head -1 000025;001;1377795616; bash-2.03# rm "bad/000025;001;1377795616;???" rm:... (17 Replies)
Discussion started by: migurus
17 Replies

4. UNIX for Dummies Questions & Answers

2 semicolons

Just wondering what 2 semicolons together after a command means (2 Replies)
Discussion started by: millsy5
2 Replies

5. Shell Programming and Scripting

search and replace, when found, delete multiple lines, add new set of lines?

hey guys, I tried searching but most 'search and replace' questions are related to one liners. Say I have a file to be replaced that has the following: $ cat testing.txt TESTING AAA BBB CCC DDD EEE FFF GGG HHH ENDTESTING This is the input file: (3 Replies)
Discussion started by: DeuceLee
3 Replies

6. Shell Programming and Scripting

Removal of last-semicolons in line with sed

Hello, I'm trying to remove an arbitrary number of semicolons at the end of each line in the input file. Input: 44;I;1000031;;;B;0137;0;;01.02.2008;03.02.2009;;;;;;;;;;;;;0028-101746;;; 45;I;1000031;;;B;0137;0;;01.02.2008;03.02.2009;;;;;;;;;;;;;0028-101746;;;;; ... (6 Replies)
Discussion started by: uioreanu
6 Replies

7. Shell Programming and Scripting

Searching for a pattern between 2 semicolons

I have logs which is having strings like below, errorMsg;; errorMsg;bad input; so I need to grep from logs file which searches for errorMsg followed by semicolon followed by any text and then ending again with semicolon. More importantly, I should not get errorMsg and having nothing... (4 Replies)
Discussion started by: gopikrish81
4 Replies

8. Shell Programming and Scripting

Adding semicolons

Lets say I wanted to add a ; before the last 6 characters of my variable how would I do this? (2 Replies)
Discussion started by: puttster
2 Replies

9. UNIX for Dummies Questions & Answers

Disappearing files

Suse 10.3 ispconfig Using as a web server, mail server. I'm the only user. These files: /var/log/httpd/ispconfig_access_log_2008_08_28 /var/log/httpd/ispconfig_access_log_2008_08_29 vanished without a trace. I still have older and newer files, but not these. I have not deleted... (5 Replies)
Discussion started by: KillerDog
5 Replies

10. UNIX for Dummies Questions & Answers

Disappearing route

I have a route that disappears when the server is rebooted. to get the route back I do: route add 65.x.x.x 10.0.x.x I go to cd /etc/inet vi config and the route is in place Anybody might know what is happening? (4 Replies)
Discussion started by: jrmontg
4 Replies
Login or Register to Ask a Question