473,320 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Unix Adding Text to corresponding lines...

grep $USER xx >> filenorman.thai

i used the above command to gain a searched list for a user and put it into a file called filenorman.thai, the following is a bit of its contents...

USER=norman.thai
MAIL=/var/spool/mail/norman.thai
PWD=/home/norman.thai
HOME=/home/norman.thai

My question is, how do i add the corresponding line number as well as a bracket to make the text look like this:-

1)USER=norman.thai
2)MAIL=/var/spool/mail/norman.thai
3)PWD=/home/norman.thai
4)HOME=/home/norman.thai
Jan 15 '08 #1
8 3055
Expand|Select|Wrap|Line Numbers
  1. awk '$0=++c")"$0' filenorman.thai>_tmp&&mv _tmp filenorman.thai
Jan 15 '08 #2
Expand|Select|Wrap|Line Numbers
  1. awk '$0=++c")"$0' filenorman.thai>_tmp&&mv _tmp filenorman.thai
Is there a method without awk cos i'm learning from the basics and i've used tmp files before but i want a way without using a tmp file. Thanks
Jan 16 '08 #3
It uses temporary file implicitly though ...

Expand|Select|Wrap|Line Numbers
  1. (rm file&&nl -s\) -w1>file)<file
Jan 16 '08 #4
It uses temporary file implicitly though ...

Expand|Select|Wrap|Line Numbers
  1. (rm file&&nl -s\) -w1>file)<file
i was told to look into loops. I'm new tho i'll have a crack at what you put in.
Jan 16 '08 #5
i was told to look into loops.[...]
I'd search google for shell scripting tutorial ...
Jan 16 '08 #6
I'd search google for shell scripting tutorial ...
Hey thanks for your time, both codes you provided for me work, i vaguely understand the last one...i just don't understand why my tutorials would ask me to look at loops.

If you have any time could you explain the nl -s\ command and w1 in your coding - (rm file&&nl -s\) -w1>file)<file

Thanks again you have been helpful
Jan 16 '08 #7
Sure,
man nl says:

nl - number lines of files
[...]
-s, --number-separator=STRING
add STRING after (possible) line number
[...]
-w, --number-width=NUMBER
use NUMBER columns for line numbers



The -s option let you specify the character after the number:
")" in our case, we need to escape it,
because it's special for the shell, the -w option let you specify
the number of columns for the line numbers, try the command
without it to see the difference.
Jan 16 '08 #8
Sure,
man nl says:

nl - number lines of files
[...]
-s, --number-separator=STRING
add STRING after (possible) line number
[...]
-w, --number-width=NUMBER
use NUMBER columns for line numbers



The -s option let you specify the character after the number:
")" in our case, we need to escape it,
because it's special for the shell, the -w option let you specify
the number of columns for the line numbers, try the command
without it to see the difference.
Ahhh thanks very much, much appreciated!
Jan 16 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Sue | last post by:
On code-behind page: (attributes set programatically for each of these elements) linkbutton added to tablecell textbox added to tablecell tablecells added to tablerow tablerow added to table...
34
by: Volker Hetzer | last post by:
Hi! I've done lots of programming for CAD, which was basically C/C++ and tcl/tk. Now, we are thinking about introducing more web based tools, programming them ourselves and right now the toolchain...
7
by: kamkwokho | last post by:
Could any answer following questions as many as you can. ii) Write a C shell script convertmin which will read in a number, thought of as representing minutes, and print out the number of...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
3
by: Ankit Aneja | last post by:
I have a strange situation and I have no idea how to solve this. Its a Recruitment Search Page,in the Admin Page, for every button click event the Admin Person has to create a checkbox on the users...
17
by: Franz Steinhaeusler | last post by:
Hello, I need a regularexpression, which trims trailing whitespaces. While with unix line endings, it works; but not with Window (Dos) CRLF's: >>> import re >>> retrailingwhitespace =...
1
by: Osoccer | last post by:
...to a different folder and in the relocated file concatenates all of the lines in one long string with a space between each line element. Here is a fuller statement of the problem: I need a...
16
by: mazwolfe | last post by:
Someone recently asked about reading lines. I had this code written some time ago (part of a BASIC-style interpreter based on H. Shildts in Art of C) to read a file with the lines ended in any...
65
by: Hongyu | last post by:
Dear all: I am trying to write to a file with full directory name and file name specified (./outdir/mytestout.txt where . is the current directory) in C programming language and under Unix, but...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.