-1

I have one big file which are contains around 500000 numbers, some of those numbers contains URl,Passwords , as you can see in my below example for my file , i would like to delete those numbers and keep only those numbers that contain Url,Password

101045
101046
101047
101048
101049            <Password>eee33ddrFDE</Password>
      <Url>http://www.example.com/9786140220447.php</Url>
--
      <Password>6tgHDDYUqLH</Password>
      <Url>http://www.example.com/9786140204102.php</Url>
101050
101051
101052
101053
101054

i have try to use cat and grep and vim with

:%s/^.\{6}//

but it will delete all numbers even those numbers which is have Url,Password that i want to keep it.

jassim mishal
  • 73
  • 2
  • 12

3 Answers3

1

You want to keep only those lines which contain password or url?.

You can use sed:

sed '/^[0-9]\+$/d'

or grep:

grep '[0-9]\+ '

Or in vim:

:g/^[0-9]\+$/d
hek2mgl
  • 152,036
  • 28
  • 249
  • 266
  • for vim i got error E486: Pattern not found: ^[0-9]\+$ and for sed & grep .. it will print all contains numbers & url,password.. like cat file – jassim mishal Mar 16 '15 at 14:03
  • Can you be more clear about what exactly is your input and what exactly is your expected output? Please add that to the question – hek2mgl Mar 16 '15 at 14:04
0

This removes all line that are only number:

awk '!/^[0-9]*$/' file 
101049            <Password>eee33ddrFDE</Password>
      <Url>http://www.example.com/9786140220447.php</Url>
--
      <Password>6tgHDDYUqLH</Password>
      <Url>http://www.example.com/9786140204102.php</Url>

Or you can use this:

awk '/Password|http/' file

Prints only lines with Password or http


Or you can clean it up some:

awk -F"[<>/]" '/Password/ {print "Password="$3} /http/ {print "Url="$5}' file
Password=eee33ddrFDE
Url=www.example.com
Password=6tgHDDYUqLH
Url=www.example.com
Jotne
  • 40,548
  • 12
  • 51
  • 55
  • I've tried awk , is good but still he remove all numbers , what I'm looking for... i want to keep that numbers which contain the url,password ,, like above ..101049 with url,password – jassim mishal Mar 16 '15 at 13:43
  • @jassimmishal Then the first example should do. It just print lines that is not single number. So all of the line is intact. – Jotne Mar 16 '15 at 13:58
  • after i run first example it will print normal contain everything ID,URL,Password – jassim mishal Mar 16 '15 at 14:22
0

If you want to get rid of lines without password/URI info, you could try with:

grep -E "[^0-9]+" filename

Casu
  • 41
  • 1
  • 3
  • thanks that's work with me & I'm sure the other answer as well will work due ,, i found there are two blank spaces after each number ..I've deleted with vim using `:%s/\s\+$//` and run the commands – jassim mishal Mar 16 '15 at 21:28