LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 01-30-2014, 12:13 AM   #1
jone kim
Member
 
Registered: Apr 2010
Posts: 185

Rep: Reputation: 16
output of wc -L in variables


how to print the output of wc -L in two different variables.

One variable contains the length part and another contains the file name.
Is there any way to do it?
 
Old 01-30-2014, 12:26 AM   #2
casualfred
Member
 
Registered: Aug 2012
Location: USA
Distribution: Slackware64-14.2
Posts: 84

Rep: Reputation: 16
I'm not sure if this is the answer you're looking for, but sometimes in scripts I do:
Code:
MYVAR=`cat theFile | wc -l`
That way you will end up with only the number.
 
Old 01-30-2014, 12:44 AM   #3
jone kim
Member
 
Registered: Apr 2010
Posts: 185

Original Poster
Rep: Reputation: 16
I think this will the whole output inside one variable. But I want to store the length part
of the output to be stored in one variable and file name in another variable.

How can I do it?
 
Old 01-30-2014, 12:54 AM   #4
casualfred
Member
 
Registered: Aug 2012
Location: USA
Distribution: Slackware64-14.2
Posts: 84

Rep: Reputation: 16
That command will give you only the number.

Example where the longest line in theFile.txt is 18 characters:
Code:
$ ./myscript.sh theFile.txt
theFile.txt
18
Content of myscript.sh:
Code:
#!/bin/bash

FILENAME="$1"
echo $FILENAME

LONGESTLINE=`cat "$1" | wc -L`
echo $LONGESTLINE
 
Old 01-30-2014, 01:52 AM   #5
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,129

Rep: Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272Reputation: 2272
first, do not use cat file | wc -L but wc -L file.
you can do the following:
Code:
a=$(wc -L filename)
line=${a#* }
lineno=${a% *}
 
  


Reply

Tags
command


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
storing the output in two different variables jone kim General 14 02-06-2014 05:14 AM
Adding variables then output to another variable stevo520 Linux - Newbie 2 07-06-2012 08:06 PM
[SOLVED] SQL Command output to bash variables chirayu11 Linux - Newbie 5 08-04-2010 08:40 AM
ambiguous output using variables in bash gwong Linux - Newbie 2 05-05-2007 09:49 PM
Scripting : Dual line output into next script as variables facets Programming 6 06-10-2004 03:28 PM


All times are GMT -5. The time now is 08:40 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration