1832423 Members
3261 Online
110042 Solutions
New Discussion

CONTROL TOTALS

 
SOLVED
Go to solution
Ferdie Castro
Advisor

CONTROL TOTALS

Hi,
I tried to use sed to list control totals for file xxx. sed -e ':set number' xxx but gives me an error. Can anyone help me?
info contents of xxx
asdasfadf
asdfadsf
adasdhgf
afasd
then when I run the script- it should give me output
1 asdasfadf
2 asdfadsf
3 adasdhgf
4 afasd
I know this is simple for you guys.
4 REPLIES 4
curt larson_1
Honored Contributor

Re: CONTROL TOTALS

use the pr command:

cat yourfile | pr -n > newfile

-nck Provide k-digit line numbering (default for k is 5). The number occupies the first k+1 character positions of each column of normal output or each line of -m output. If c (any nondigit character) is given, it is appended to the line number to separate it from whatever follows (default for c is a tab).
Michael Tully
Honored Contributor
Solution

Re: CONTROL TOTALS

Sorry I haven't time for a test, but here are some examples from one of the tutorial sites that are around.

NUMBERING:

# number each line of a file (simple left alignment). Using a tab (see
# note on '\t' at end of file) instead of space will preserve margins.
sed = filename | sed 'N;s/\n/\t/'

# number each line of a file (number on left, right-aligned)
sed = filename | sed 'N; s/^/ /; s/ *\(.\{6,\}\)\n/\1 /'

# number each line of file, but only print numbers if line is not blank
sed '/./=' filename | sed '/./N; s/\n/ /'

Here's the site for future reference.
http://packetstormsecurity.nl/programming-tutorials/sed/sedtut_9.txt
Anyone for a Mutiny ?
Rajeev  Shukla
Honored Contributor

Re: CONTROL TOTALS

Hi,
Can you clear one thing,
Do you want to put the line numbers or you want to count the number of occurances of a word and total them?...


Ferdie Castro
Advisor

Re: CONTROL TOTALS

Hi all, thanks for the help. It worked for both.