01-18-2006
Add a column at the end of all the lines in a file
Hi Guys,
I am very much new to UNIX. I dont have much basics of coding in UNIX, so please help me out of thi ssituation.
I have a file say for ex: ABC.dtd and it contains "|" delimited data as
test1|testing|test3|moving
past1|runing|test4|going
I need to add a column at the end of each line as shown below.
test1|testing|test3|moving|D
past1|runing|test4|going|D
for this purpose I am using the command :searches the end of the line i.e "$" and then replaces with "D".
%s/$/D/g
The problem is before the search begins, first I need to implement a function that picks up the file from the specified location and performs search and replace and pushes back thhe file to the original location.
This overall function I need to implement in a ksh script.
Could you please help me out of this?????????
Thanks in advance.
ruthless
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi all
I need to strip blank lines from the end of a file. I have searched and found topics on how to strip lines from the entirety of a file - however I need to limit this to only the last 3-4 lines.
Any ideas?
Thanks (4 Replies)
Discussion started by: saabir
4 Replies
2. Shell Programming and Scripting
Hi,
I want to add \n as a EOF at the end of file if it does't exist in a single command. How to do this?
when I use command
echo "1\n" > a.txt
and
od -c a.txt
0000000 1 \n \n
0000003
How does it differentiate \n and eof in this case?
Regards,
Venkat (1 Reply)
Discussion started by: svenkatareddy
1 Replies
3. Shell Programming and Scripting
I have a text file with two coulmn
first column is just used in to show the line number, these line number are not there in the real file.
I want to delete the line 16(in this file) here, even tough there is no data inside it . this empty line is causing me a problem by throwing me garbage... (12 Replies)
Discussion started by: shashi792
12 Replies
4. Shell Programming and Scripting
i have a file in following format
1 32 3
4 6 4
4 45 1
45 4 61
54 66 4
5 65 51
56 65 1
12 32 85
now here the total number of lines are 8(they vary each time)
Now i want to select only those lines in which the values... (6 Replies)
Discussion started by: vaibhavkorde
6 Replies
5. Shell Programming and Scripting
I have this:
301205 0000030000041.49000000.00 2011111815505 908
301205 0000020000029.10000000.00 2011111815505 962
301205 0000010000027.56000000.00 2011111815505 3083
312291 ... (2 Replies)
Discussion started by: herot
2 Replies
6. Shell Programming and Scripting
I'd like to write up notes in a relatively readable format and then use a shell script to add LaTeX formatting. Specifically, I'm trying to figure out how to add the LaTeX newline character (\\) to the end of lines without \begin{} or \end{} statements
example notes file:
\begin{enumerate}
--... (2 Replies)
Discussion started by: icskittles
2 Replies
7. Shell Programming and Scripting
I really can't figure this one out.
I have 2 files, one file is a list of hostnames and the other is a list of their corresponding IPs:
fileA:
example.com
another.org
thirdie.net
fileB:
1.1.1.1
2.2.2.2
3.3.3.3
I want to create a fileC that looks like:
example.com 1.1.1.1... (2 Replies)
Discussion started by: zstar
2 Replies
8. UNIX for Dummies Questions & Answers
Hello All,
this is my first post so I don't know if I am doing this right.
I would like to append entries from a series of strings (contained in a text file) consecutively at the end of specifically labeled lines in another file.
As an example:
- the file that contains the values to be... (3 Replies)
Discussion started by: gus74
3 Replies
9. Shell Programming and Scripting
Hi,
I have data with approximately 300 columns.
I want to add a column to the end of each column with the value "1".
Is there a way that I can do this is ´awk´ without having to specify each individual column.
For instance, my data looks like:
pvb 1 2 3 4 5 ....... 300
fdh 3 4 5 2 4 ......... (4 Replies)
Discussion started by: owwow14
4 Replies
10. UNIX for Dummies Questions & Answers
I have a log file which lists groups and users in the following format
GROUP1
user1
user2
user3
GROUP2
user4
user5
user6
GROUP3
user7
user8
I need to change the format to:
user1|GROUP1
user2|GROUP1
user3|GROUP1
user4|GROUP2 (3 Replies)
Discussion started by: Angela S
3 Replies
exit(1) User Commands exit(1)
NAME
exit, return, goto - shell built-in functions to enable the execution of the shell to advance beyond its sequence of steps
SYNOPSIS
sh
exit [n]
return [n]
csh
exit [ ( expr )]
goto label
ksh
*exit [n]
*return [n]
DESCRIPTION
sh
exit will cause the calling shell or shell script to exit with the exit status specified by n. If n is omitted the exit status is that of
the last command executed (an EOF will also cause the shell to exit.)
return causes a function to exit with the return value specified by n. If n is omitted, the return status is that of the last command exe-
cuted.
csh
exit will cause the calling shell or shell script to exit, either with the value of the status variable or with the value specified by the
expression expr.
The goto built-in uses a specified label as a search string amongst commands. The shell rewinds its input as much as possible and searches
for a line of the form label: possibly preceded by space or tab characters. Execution continues after the indicated line. It is an error to
jump to a label that occurs between a while or for built-in command and its corresponding end.
ksh
exit will cause the calling shell or shell script to exit with the exit status specified by n. The value will be the least significant 8
bits of the specified status. If n is omitted then the exit status is that of the last command executed. When exit occurs when executing
a trap, the last command refers to the command that executed before the trap was invoked. An end-of-file will also cause the shell to exit
except for a shell which has the ignoreeof option (See set below) turned on.
return causes a shell function or '.' script to return to the invoking script with the return status specified by n. The value will be the
least significant 8 bits of the specified status. If n is omitted then the return status is that of the last command executed. If return
is invoked while not in a function or a '.' script, then it is the same as an exit.
On this man page, ksh(1) commands that are preceded by one or two * (asterisks) are treated specially in the following ways:
1. Variable assignment lists preceding the command remain in effect when the command completes.
2. I/O redirections are processed after variable assignments.
3. Errors cause a script that contains them to abort.
4. Words, following a command preceded by ** that are in the format of a variable assignment, are expanded with the same rules as a vari-
able assignment. This means that tilde substitution is performed after the = sign and word splitting and file name generation are not
performed.
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
|Availability |SUNWcsu |
+-----------------------------+-----------------------------+
SEE ALSO
break(1), csh(1), ksh(1), sh(1), attributes(5)
SunOS 5.10 15 Apr 1994 exit(1)