I'm trying to add a new line after finding a specific String.
That is my string:
volumes:
-
and I want to change that file to:
volumes:
-
That my code:
but that do nothing
do you have an idea!?
Please always tell us what operating system and shell you're using when you start a new thread in the UNIX for Beginners Questions & Answers forum. Although many utilities are available on all BSD, Linux, and UNIX systems, the options they provide and the output they produce can vary from system to system and shell to shell. If we know what environment you're working in, it helps us make suggestions that will work in your environment without having to guess what your environment might be.
It isn't at all clear to me what you're trying to do.
Does the file you want to edit actually contain the text ${DIR_WORK} or does the file contain what the expansion of the shell variable DIR_WORK expands to?
Can that line appear more than once in a file?
Can anything else appear on that line? (It doesn't look like you're trying to only match lines that exactly match that string; it looks like you're only trying to match lines that contain that string possibly with other text before and/or after what is in your search string?)
When that line is found in a file, do you want to add two lines to thee end of that file? Or do you want to add those two lines immediately following the line you found?
By calling the variable you're searching for lastLine are you indicating that the line you're looking for should only appear as the last line in that file?
This User Gave Thanks to Don Cragun For This Post:
I'm trying to insert a single character at position 11 in everyline of a file.
My input file looks like this:
456781 ~Y~12345
456782 ~N~12300
and I want my output to look like this:
45678~1 ~Y~12345
45678~2 ~N~12300
I tried the following awk code, but it's not working:... (3 Replies)
Hi,
I have a log file generated by a tool which has the following look :
/tmp/releases/directory/datefilename1_release_date.zip
/tmp/releases/directory/datefilename2_release_date.zip
/tmp/releases/directory/datefilename3_release_date.zip... (8 Replies)
Hi All,
I have below type file.
abc|asd|pqr|2|2|2
asc|qwe|scf|5|4|4
Pipe location and count is dynamic and coming from a variable.
I want to change it to below files.
(chnage the first pipe to 3 pipes)
abc|||asd|pqr|2|2|2
asc|||qwe|scf|5|4|4
(chnage the second pipe to 4 pipes)... (1 Reply)
Hi,
I need to add Pipe (|) at 5th and 18th position of all records a file. How can I do this?
I tried to add it at 5th position using the below code. It didnt work. Please help!!!
awk '{substr($0,5,1) ~ /|/}{print}' $input_file > $temp_file (1 Reply)
I have a file and I can get the line with a specific pattern. I want to inset # on start of the line.
file.text
====
aa bb cc
bb hh kk
kk ll yy
dd aa kk
rr tt aa
I want to comment out the line with contain "aa"
after running the script
file.text
====
#aa bb cc
bb hh kk
kk ll... (7 Replies)
Hi,
Anyone can help me in Solaris command on how to insert a file at specific line.
I want file1.sql content to be inserted on file2.sh after "recover database using backup controlfile until cancel".
# file1.sql
/archivelogs/927_822338133.arc
/archivelogs/671_822338107.arc... (3 Replies)
Hi,
If my first character of a line starts with 2 then after 5th charecter newline character should be inserted.
Input.txt:
a1234567890
2222300007
bsdfsdf888999999
ssdfkjskfdjskfdjd
2899900000000099999999999999
28887777
999999999999999999
Output.txt:
a1234567890
22223
00007... (8 Replies)
Hi All,
I am trying to write a shell script where it should insert character 'I' in 180th position of each line(except first and last line) of the file. Below is the script
for file in /home/test/bharat/*.RET
do
# Process file
echo "File Name=" $file
#l_fileName="${file##*/}"
... (19 Replies)
I will appreciate if you help me here in this script in Solaris Enviroment.
Scenario:
i have 2 files :
1) /tmp/TRANSACTIONS_DAILY_20180730.txt:
201807300000000004
201807300000000005
201807300000000006
201807300000000007
201807300000000008
2)... (10 Replies)