3

I have the next output:

Date Time: June 22 12:40:00

Product User Host IP

Software User User *.***.***.***
Software1 User User *.***.***.***

I tried some functions with sed and awk, but is not working; I want that the text stays at the next way:

Date Time: June 22 12:40:00

Product User Host

Software User User 
Software1 User User

I have the next command:

$ cat Mathematica_06-* | \
  grep -w -A 4 -B 5 "AER8\|User\|User1\|User2\|User3\|User4\|User5\|User6\|User7\|User7\|User8\|User9\|User10\|User11\|User11\|User12\|User13\|User14\|User15\|User16\|User17\|User18\|User19" | \
  awk '{print $1,$3,$4,$5,$7}' | \
  egrep -v
    > Output.log

I tried to add at final egrep -v "|IP" but if I put the line in that command, I obtained the next output:

Date Time: June 22 12:40:00

Softare User User 
Software User User

Is there any other way to delete the "IP" and the "*" parts without affect the rest of the line?

2
  • 1
    Are the *.***.***.*** literal or have you redacted actual IP addresses?
    – jesse_b
    Commented Jul 26, 2018 at 21:32
  • Yes is a public IP, I don't want make public but the line contains the same length Commented Jul 26, 2018 at 22:01

3 Answers 3

3

Using sed

sed -i -e 's/\*.*//g' -e 's/ IP//g' -e '\$^Syntax.*$d' File*

This should also work:

awk '/Date/{print $0} /^Product|^Soft/{print $1" "$2" "$3} /^$/' File*
3

Here's one way with awk. The NR variable represents the record number; just print it if its the first. awk counts fields from one, so you are saying you only want the first three thereafter:

awk 'NR==1 {print;next};{print $1,$2,$3}' 
1

Using sed to delete the last word and any spaces or tabs before it on lines 5 and onwards:

$ sed -E '5,$s/[[:blank:]]*[^[:blank:]]+$//' file
Date Time: June 22 12:40:00

Product User Host IP

Software User User
Software1 User User

The 5,$ addresses every line from line 5 onwards, and the substitution that acts on these lines will remove any number of spaces or tabs followed by something that is made up from non-spaces and non-tabs at the end of the line.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .