Solved search by sed or awk

December 28, 2018 at 12:16:52
Specs: Windows Vista
I have file where are two important number per row, and I need to search only that numbers.

File contain as below. (important number can be everywhere in row)

row 1 Word1 ; word2 ; 222 ; first important number 123456 ; some_text ; second important number 323232
row 2 Word1 ; word2 ; first important number 55555 ; second important number 3434343323232 ; some_text
e.t.c.

and I need only important number as below

first important number 123456 ; second important number 323232
first important number 55555 ; second important number 3434343323232

How this can be done with awk or sed or any commands


See More: search by sed or awk

Report •

#1
January 1, 2019 at 09:52:43
✔ Best Answer
I think you are asking to parse datafile.txt where the field seperater is a semi-colon, and search each field for 'first important number' and 'second important number' strings. you can do that with awk:

#!/bin/bash

awk  ' BEGIN { FS = ";" }
{
for (i=1; i<=NF; i++)
   {
   if($i ~ /first important number/)
      printf("%s", $i)
   if($i ~ /second important number/)
      printf("%s\n", $i)
   }
}' datafile.txt


Let me know if you have any questions or comments

message edited by nails


Report •

#2
January 1, 2019 at 22:58:57
Hi Nails.

Well done. Thank you so much, I got what I wanted.

johan


Report •
Related Solutions


Ask Question