Delimit the out of wc -l command.


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Delimit the out of wc -l command.
# 1  
Old 05-06-2012
Delimit the out of wc -l command.

Hi All,

Greetings !!! Smilie

Am having issues with wc -l command.

My requirement is to delimit the output with comma seperated values and use that file as input in informatica.

Code:
wc -l *.ksh

Output :

Code:
      16 espress_raise.ksh
     173 espresso_monitoring.ksh
     189 total

Required Output :

Code:
16,espress_raise.ksh
173,espresso_monitoring.ksh

I tried to eliminate the spaces & delete the last line using the following command

Code:
wc -l *.ksh |  sed 's/ //g' | sed '$d'

But am not able to delimit it.

Kindly help me in achieving the same.

Regards,
Srivignesh KN

Last edited by Scrutinizer; 05-06-2012 at 07:45 AM.. Reason: code tags
# 2  
Old 05-06-2012
Hi srivignesh.kn,

One way:
Code:
$ wc -l *.ksh | sed -e '$d; s/[ ]/,/'
16,espress_raise.ksh
173,espresso_monitoring.ksh

This User Gave Thanks to birei For This Post:
# 3  
Old 05-06-2012
Code:
wc -l *.ksh | awk '$1=$1' OFS=, | sed '$d'

Code:
wc -l *.ksh | sed '$d; s/^ *//;s/ /,/'

This User Gave Thanks to Scrutinizer For This Post:
# 4  
Old 05-07-2012
Thanks Birei & Scrutinizer,

The following command worked as expected.

Code:
wc -l *.ksh | sed '$d; s/^ *//;s/ /,/'

Regards.
Srivignesh KN

Last edited by Scrutinizer; 05-07-2012 at 01:49 AM.. Reason: code tags
# 5  
Old 05-07-2012
try this...

Code:
 
 wc -l * | nawk -v OFS=, '!/total/ {$1=$1;print}'

# 6  
Old 05-07-2012
@itka, what if there is a file with "total" in the name somewhere? That does not seem hypothetical, whereas the wc "total" line is always the last line...
This User Gave Thanks to Scrutinizer For This Post:
# 7  
Old 05-07-2012
this will work

Code:
 
wc -l *.ksh | nawk -v OFS=, '$2!~/^total$/{$1=$1;print}'

Code:
 
for i in *.sh; do perl -lane 'END{print $. . "," . $ARGV}' "$i"; done

 
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 delimit the fields of a input file which has special characters?

Hi All, I am a newbie to Shell scripting. I have a requirement to Delimit the file fields of a Input file having special characters and spaces with ";". Input File ---------------------------------- Server Port ---------------------------------- Local ... (5 Replies)
Discussion started by: Suganbabu
5 Replies

2. Shell Programming and Scripting

Delimit file based on character length using awk

Hi, I need help with one problem, I came across recently. I have one input file which I need to delimit based on character length. $ cat Input.txt 12345sda231453 asd760kjol62569 sdasw4g76gdf57 And, There is one comma separated file which mentions "start of the field" and "length... (6 Replies)
Discussion started by: Prathmesh
6 Replies

3. Shell Programming and Scripting

How to remove space and delimit a csv file?

Hi All , I am facing a small challenge i need unix command to remove space as well as replace "|" to "," in a csv file . original file : A | B | c | D E | F | G | H I | J | K | L P | M | N | O Expected o/p: A,B,c,D E,F,G,H I,J,K,L P,M,N,O (4 Replies)
Discussion started by: Sweety532
4 Replies

4. Shell Programming and Scripting

Perl script to delimit size of strings

Hello, I have a huge file of over 2,00,00,00 strings in UTF8 format. I have managed to write a script in Perl which sorts them neatly as per their Unicode ranges. However I am now stuck with a script which will pipe out all strings between 3 and 20 letters/characters. I am not very good at... (2 Replies)
Discussion started by: gimley
2 Replies

5. UNIX for Dummies Questions & Answers

passing command output from one command to the next command in cshell

HI Guys, I hope you are well. I am trying to write a script that gets executed every time i open a shell (cshell). I have two questions about that 1) I need to enter these commands $ echo $DISPLAY $ setenv $DISPLAY output_of_echo_$display_command How can i write a... (2 Replies)
Discussion started by: kaaliakahn
2 Replies

6. UNIX for Advanced & Expert Users

Delimit the Folder Size come under Webapps dir

Hi all, Great thanks to all for support till today..today i came here for 1 new issue :-( in our organization we are developing a job portal web application for a client. using Apache-tomcat we are hosting this application, now i need to delimit the applications directory comer under the webapps... (1 Reply)
Discussion started by: anishkumarv
1 Replies

7. Shell Programming and Scripting

awk: round output or delimit output of arithmatic string

I have a file with the following content. > cat /tmp/internetusage.txt 6709.296322 30000 2/7/2010 0.00I am using the following awk command to calculate a percentage from field 1 and 2 from the file. awk '{ print $1/$2*100 }' /tmp/internetusage.txt This outputs the value "22.3643" as a... (1 Reply)
Discussion started by: jelloir
1 Replies

8. Solaris

how to delimit a colon

I want to know how to delimit a colon in a file name while scp ing from one host to other host. I used forward slash(\) but that is not working. (1 Reply)
Discussion started by: rogerben
1 Replies

9. Shell Programming and Scripting

cat or cut to delimit csv?

Hi, Im a pretty large noob to linux/perl etc and im trying to use mysql slurp to take a delimited file and import it into mysql using stdin (in the hope its faster) mysqlslurp - slurp <STDIN> into a MySQL table - search.cpan.org Christopher Brown / MySQL-Slurp - search.cpan.org Using... (3 Replies)
Discussion started by: newtony
3 Replies

10. Shell Programming and Scripting

How to delimit a flat file with records with SED

Hi gurus, hoping someone can help with a sed line that can do the following... I have a flat file with about 1000 records, but in order to import into openoffice spreadsheet, I need to create a delimited file. I'd like to do 2 things with the SED command: 1- add a pipe character "|" at the end... (4 Replies)
Discussion started by: RogCor
4 Replies
Login or Register to Ask a Question