Question & Answer
Question
This document explains how to change the only second line in a file to a string of characters using the SED command.
Answer
Environment
AIX 5L To substitute a particular line in a file with a different string of characters, use the following format:# sed "[linenumber]s/pattern/replacement/flags" filename
Where
linenumber - line number that you want to replace in the file
pattern - string of characters you want to change on linenumber
replacement - string of characters that will replace the pattern
flags - number of occurrences (in this case, you are only changing the first occurrence)
The following example uses a file called filename. You will replace the second line "5678" with a string of ones, "1111".
-
Display the file you want to change.
# cat filename 1234 5678 9123 4567
-
Change line 2 to your new string of characters. This example is
using "1111".
# sed "2s/5678/1111/1" filename 1234 1111 9123 4567
Related Documentation
For more in-depth coverage of this subject, refer to the Software Documentation Library, which can be accessed online:
AIX Version 5L:
http://publib16.boulder.ibm.com/pseries/
Historical Number
isg1pTechnote1196
Was this topic helpful?
Document Information
Modified date:
17 June 2018
UID
isg3T1000495