06-04-2008
Replacing a string in nth line
Hello All,
How to replace a string in nth line of a file using sed or awk.
For Ex: test.txt
Line 1 : TEST1 TEST2 TEST3
Line 2 : TEST1 TEST2 TEST3 TEST4
Line 3 : TEST1 TEST2 TEST3 TEST5
Line 4 : TEST1 TEST2 TEST3 TEST6
Line 5 : TEST1 TEST2 TEST3 TEST7
i want to go to 4th line of a file and replace the word TEST2 in that line with the word DEV2.
Note : this is not a homework. just need some ideas in SED or AWK
Thanks
Rahul
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
Hi,
I have several files with data that have to be imported to a database. These files contain records with separator characters. Some records are corrupt (2 separators are missing) and I need to correct them prior to importing them into the db.
Example:
... (5 Replies)
Discussion started by: stresing
5 Replies
2. UNIX for Advanced & Expert Users
All,
Is there any way out to display the nth line before the string is matched ???
Eg : If i have a file which has the following contents and if i want to get the
3rd line before the string is matched
a
b
c
d
e
f
if i give the input as f and lines before the match as 3 then it should... (5 Replies)
Discussion started by: helper
5 Replies
3. UNIX for Dummies Questions & Answers
hi,
i currently have a file with columns similar to this
customer name owed
CID123 John 300
CID342 harry 500
at present i use use awk to find the amount owed by the customer using the customer ID (CID).
if the customer spends more money how would i go about using sed/awk etc to... (2 Replies)
Discussion started by: skinnygav
2 Replies
4. Shell Programming and Scripting
Hi,
Can anyone help me know how to replace a string with the new line
for ex:
file1
val1 or val2 or val3 or
I need to replace the "or" with new line.
Thanks in advance (2 Replies)
Discussion started by: mr_manii
2 Replies
5. Shell Programming and Scripting
Hi
I have requirement to find nth occurrence in a file and capture data from with in lines (between lines)
Data in File.
<QUOTE>
<SESSION>
<ATTRIBUTE NAME='Parameter Filename' VALUE='file1.parm'/>
<ATTRIBUTE NAME='Service Name' VALUE='None'/>
</SESSION>
<SESSION>
<ATTRIBUTE... (6 Replies)
Discussion started by: tmalik79
6 Replies
6. Shell Programming and Scripting
Is there an awk script that can easily perform the following operation?
I have a data file that is in the format of
1944-12,5.6
1945-01,9.8
1945-02,6.7
1945-03,9.3
1945-04,5.9
1945-05,0.7
1945-06,0.0
1945-07,0.0
1945-08,0.0
1945-09,0.0
1945-10,0.2
1945-11,10.5
1945-12,22.3... (3 Replies)
Discussion started by: ncwxpanther
3 Replies
7. Shell Programming and Scripting
Hi All,
I am very new to shell scripting and tried to search this in the forum but no luck.
Requirment:
I have an input file which is comma separated. I need to replace the value in 4th column with another value. This has to happen for all the lines in the file.
Sample data:
Input... (2 Replies)
Discussion started by: arunkumarsd
2 Replies
8. Shell Programming and Scripting
hi
i need to get the 3rd line in a string.
actually, not sure if it's a string, list, array, or something else. I'm using grep to retrieve all the numbers in a string-- in the console, it displays as multiple lines:
$ echo "Sink 0: reference = 0: 153% 1: 45%, real = 0: 62%" | grep -o *
0... (4 Replies)
Discussion started by: johnywhy
4 Replies
9. Shell Programming and Scripting
My file (the output of an experiment) starts off looking like this,
_____________________________________________________________
Subjects incorporated to date: 001
Data file started on machine PKSHS260-05CP
**********************************************************************
Subject 1,... (9 Replies)
Discussion started by: samonl
9 Replies
10. Shell Programming and Scripting
Hello,
Environment:
I am under Ubuntu 18.04 bionic. I have an sql file consisting of 10K lines.
Objective:
What I am trying to attain is to remove everything coming after 2nd tab in each line. While searching for the answer, I found two answers and both gave expected result just for the first... (2 Replies)
Discussion started by: baris35
2 Replies
LEARN ABOUT DEBIAN
gtypist
GTYPIST(1) User Commands GTYPIST(1)
NAME
gtypist - a typing tutor with lessons for different keyboards and languages
SYNOPSIS
gtypist [ options... ] [ script-file ]
DESCRIPTION
`gtypist' is a typing tutor with several lessons for different keyboards and languages. New lessons can be written by the user easily.
OPTIONS
-b --personal-best
track personal best typing speeds
-e % --max-error=%
default maximum error percentage (default 3.0); valid values are between 0.0 and 100.0
-n --notimer
turn off WPM timer in drills
-t --term-cursor
use the terminal's hardware cursor
-f P --curs-flash=P
cursor flash period P*.1 sec (default 10); valid values are between 0 and 512; this is ignored if -t is specified
-c F,B --colours=F,B
set initial display colours where available
-s --silent
don't beep on errors
-q --quiet
same as -s, --silent
-l L --start-label=L
start the lesson at label 'L'
-w --word-processor try to mimic word processors
-k --no-skip
forbid the user to skip exercises
-i --show-errors
highlight errors with reverse video
-h --help
print this message
-v --version
output version information and exit
-S --always-sure
do not ask confirmation questions
--banner-colors=F,B,P,V set top banner colours (background, foreground,
package and version respectively)
--scoring=wpm,cpm
set scoring mode (words per minute or characters per minute)
If not supplied, script-file defaults to '/usr/local/share/gtypist/gtypist.typ'. The path $GTYPIST_PATH is searched for script files.
EXAMPLES
To run the default lesson in english `gtypist.typ':
gtypist
To run the lesson in spanish:
gtypist esp.typ
To instruct gtypist to look for lesson `bar.typ' in a non standard directory:
GTYPIST_PATH="/home/foo" gtypist bar.typ
To run the lesson in the file `test.typ' of directory `temp', starting at label `TEST1', using the terminal's cursor, and run
silently:
gtypist -t -q -l TEST1 /temp/test.typ
AUTHOR
Written by Simon Baldwin
REPORTING BUGS
Report bugs to bug-gtypist@gnu.org
COPYRIGHT
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Simon Baldwin.
Copyright (C) 2003, 2004, 2008, 2011 GNU Typist Development Team. This program comes with ABSOLUTELY NO WARRANTY; for details please see
the file 'COPYING' supplied with the source code.
This is free software, and you are welcome to redistribute it under certain conditions; again, see 'COPYING' for details. This program is
released under the GNU General Public License.
SEE ALSO
The full documentation for gtypist is maintained as a Texinfo manual. If the info and gtypist programs are properly installed at your
site, the command
info gtypist
should give you access to the complete manual.
gtypist 2.9.1 November 2011 GTYPIST(1)