473,396 Members | 1,927 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,396 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 3057
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.