Delimiter in output file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Delimiter in output file
# 1  
Old 11-01-2011
Delimiter in output file

Hello,

I am trying to find the record count in a specific folder,
Here is the part of the code
Code:
===========================
STARTDATE=`date +"%y%m%d%H%M"`
  for i in `ls *.DAT`
                do
                   wc -l $i >> /XYZ/SrcFiles/"Record_counts"$STARTDATE.csv
                 done

Result will be the record count followed by the file name for each row

555 FILE1.DAT
666 FILE2.DAT ....
How can I put the delimeter comma ',' or TAB for each rows
555,FILE1.DAT
666,FILE2.DAT ....

Thanks,

Moderator's Comments:
Mod Comment Video tutorial on how to use code tags in The UNIX and Linux Forums.
# 2  
Old 11-01-2011
That's a useless use of ls * and dangerous use of backticks.

You also don't have to reopen the same file 9,000 times to write 9,000 lines.

You also don't have to run wc 90 times to process 90 files.

Run wc -l once, then use awk to
1) separate output with "," -v OFS=","
2) ignore the total line if($2 != "total")
Code:
wc -l *.DAT | awk -v OFS="," '{ if($2 != "total") print $1,$2; }' > out.txt

# 3  
Old 11-01-2011
Thanks for the reply, and agree with the code change.
with a minor change, it works great.
Code:
wc -l *.DAT | awk -v':' 'BEGIN{OFS=",";} {if($2 != "total") print $1,$2;}'

Thx again,

Last edited by Franklin52; 11-02-2011 at 04:11 AM.. Reason: Please use code tags, thank you
This User Gave Thanks to Shanks For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to combing output of cut commands with a delimiter?

While looping through a file, I am cutting different length of characters (based on their length) like columns and want to produce the output in a separate file with different columns being separated by a comma. How to achieve this with an online command. I don't want to create multiple variables... (8 Replies)
Discussion started by: mady135
8 Replies

2. Shell Programming and Scripting

Perl Code to change file delimiter (passed as argument) to bar delimiter

Hi, Extremely new to Perl scripting, but need a quick fix without using TEXT::CSV I need to read in a file, pass any delimiter as an argument, and convert it to bar delimited on the output. In addition, enclose fields within double quotes in case of any embedded delimiters. Any help would... (2 Replies)
Discussion started by: JPB1977
2 Replies

3. Shell Programming and Scripting

How to set output delimiter?

Hello,All Suppose I have a file like following: aaa;bbb;ccc ddd;eee;fffI want the output like: aaa|bbb|ccc ddd|eee|fffTo do this, i wrote the code: awk 'BEGIN{FS=";";OFS="|"} {print}' myfileHowever, the output is still using ; as the delimter. What did I do wrong? Thanks. (5 Replies)
Discussion started by: littlewenwen
5 Replies

4. Shell Programming and Scripting

Shell script to put delimiter for a no delimiter variable length text file

Hi, I have a No Delimiter variable length text file with following schema - Column Name Data length Firstname 5 Lastname 5 age 3 phoneno1 10 phoneno2 10 phoneno3 10 sample data - ... (16 Replies)
Discussion started by: Gaurav Martha
16 Replies

5. UNIX for Advanced & Expert Users

File Delimiter

Hi All, I woul like to know with out opening a file in unix ,how we can find out what is the delemeter in that file... Thanks.. edit by bakunin: changed thread title to "delimiter" so it can be found. (4 Replies)
Discussion started by: raju4u
4 Replies

6. UNIX for Dummies Questions & Answers

LINUX - How to remove the final delimiter from a command output

Hi All, I am trying to list the various dates for which the file is available in a directory using the command below, (& subsequently pass the command output to a loop) Command : ls dir|grep 'filename'|cut -d '_' -f1|cut -c1-8|tr '\n' ',' However, it is giving me an extra comma... (6 Replies)
Discussion started by: dsfreddie
6 Replies

7. Shell Programming and Scripting

How to cut by delimiter, and delimiter can be anything except numbers?

Hi all, I have a number of strings like below: //mnt/autocor/43°13'(33")W/ and i'm trying to get the numbers in this string, for example 431333 please help thanks ahead (14 Replies)
Discussion started by: sunnydanniel
14 Replies

8. UNIX for Dummies Questions & Answers

set output delimiter as tab in cut command

I can not make it work, it prints \t rather than introduce tabs. cut -d "," -f 4,8 Samples.csv --output-delimiter="\t" | sort > out Since I am running this command within a shell script, I tried manually inserting tab in this command, still does not work. I am using bash shell Suggestions... (8 Replies)
Discussion started by: analyst
8 Replies

9. Shell Programming and Scripting

awk output field delimiter

Dear All, 1.txt (tab in between each value in a line) a b c a b c a c d you can see below, why with ~ i can output with tab, but = cannot? # awk -F'\t' '$2 ~ /b/' 1 a b c a b c # awk -F'\t' '$2 = "b"' 1 a b c a b c a b d ... (1 Reply)
Discussion started by: jimmy_y
1 Replies

10. Shell Programming and Scripting

Substring based on delimiter, finding last delimiter

Hi, I have a string like ABC.123.XYZ-A1-B2-P1-C4. I want to delimit the string based on "-" and then get result as only two strings. One with string till last hyphen and other with value after last hyphen... For this case, it would be something like first string as "ABC.123.XYZ-A1-B2-P1" and... (6 Replies)
Discussion started by: gupt_ash
6 Replies
Login or Register to Ask a Question