After lots of reading I figured out how to use sed to parse my file.
This file is called services.txt:
I have a text-file with on each line a service-name in it, called names.txt:
I want to use a bash script that uses a while loop to read each line from names.txt and then print out the serivice-id from the services.txt file.
The service-id is the line -before- the name in services.txt.
so for example:
The service-id of "BravaNL" would be 00a1:ffff0000:0018:01f4:1:477
After lots of searching on this board, I almost got it right using this script:
I have the following: sed -n -e "/^$line$/{x;p;q;};h"
Where $line would be the service-name from names.txt.
The following rules apply:
Sed must print the line before the search-result: done
Sed must only find complete matches for the service-names: done
If sed find multiple matches it should only process the first: done
Sed should be able to handle service-names with a slash "/" in it: FAIL
It works for all names except for the ones with a / in them:
I cannot put a break "\" in the $line.
So I would like to use another delimiter and make sed ignore the slashes.
Is this possible?
Last edited by rbatte1; 01-13-2017 at 10:12 AM..
Reason: Added ICODE tags
I have a file with millions of rows that I need to add a delimiter and a new field with a zero to the end of each row. (its too big to open and do a find and replace regex)
I'm looking for the next line '\n' and need to replace it with a Unit Separator (hex \037) 0 \n.
I've tried the... (2 Replies)
I have file which contains around 5000 lines.
The lines are fixed legth but having no delimiter.Each line line contains nearly 3000 characters.
I want to delete the lines
a> if it starts with 1 and if 576th postion is a digit i,e 0-9
or
b> if it starts with 0 or 9(i,e header and footer)
... (4 Replies)
Hello,
I want to send tcpflow dump to a TCP port in HEX data, to send with netcat i need to convert to HEX and add \\x before each HEX bytes, to do this i use this line:
tcpflow -i -C dst port | xxd -p | sed 's/../&\\\\x/g;s/ $//' | nc the output on the listening end:... (3 Replies)
HI all,,
I hve defined something like
set data = /data/2012/text
while using
sed 's/$data//g'
I am getting error as:I understand this is due to / slash,but is there any way out of it....
sed: -e expression #1, char 12: unknown option to `s'
Thakns in adv. (6 Replies)
Hi,
I'm having a bit of trouble replacing sed's delimiter from a slash to a pipe.
This works...
sed '/INSERT INTO/s/\${TD_LOAD_DB}/NUC_PL_LOAD/g' sql_file.sql
But this doesn't
sed "|INSERT INTO|s|\${TD_LOAD_DB}|NUC_PL_LOAD|g" sql_file.sql (2 Replies)
Hi,
Extremely new to Perl scripting, but need a quick fix without using TEXT::CSV
I need to read in a file, pass any delimiter as an argument, and convert it to bar delimited on the output. In addition, enclose fields within double quotes in case of any embedded delimiters.
Any help would... (2 Replies)
I need to find and replace a date format in a SQL script with sed. The original lines are like this:
ep.begin_date, ep.end_date, ep.facility_code,
AND ep.begin_date <= '01-JUL-2019'
ep.begin_date, ep.end_date, ep.facility_code,
AND ... (15 Replies)
I am trying to do this with one small tweak. I would also like to use a space as a delimiter.
sed 's/ */\
/g' file
This is what my file looks like.
server1, server2, server3
server4 server5 server6
I would like it to look like this.
server1
server2
server3
server4 ... (6 Replies)