TEXT file filtering... using shellscripting!!!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • superc0red
    New Member
    • Feb 2007
    • 5

    TEXT file filtering... using shellscripting!!!

    Hey,

    How i can open a text file using shellscripting,
    and new lines?

    for example i have the following text file:

    -------[test.txt]-------------
    Five Moroccans and a Syrian are charged
    with 191 murders and 1,755 attempted
    murders. A Spaniard is accused of 192
    murders and 1,755 attempted murders.
    Two of these seven - Jamal Zougam
    and Abdelmajid Bouchar - are accused
    of actually planting bombs.
    ----------------------------------

    I want to add these lines:

    test line 1
    test line 2

    between "murders. A Spaniard is accused of 192" &
    "murders and 1,755 attempted murders." using shellscripting

    and the out file will be:

    -------[out.txt]-------------
    Five Moroccans and a Syrian are charged
    with 191 murders and 1,755 attempted
    murders. A Spaniard is accused of 192
    test line 1
    test line 2
    murders and 1,755 attempted murders.
    Two of these seven - Jamal Zougam
    and Abdelmajid Bouchar - are accused
    of actually planting bombs.
    ----------------------------------

    thanx alot, sorry for my poor english!!
  • cybervegan
    New Member
    • Jan 2007
    • 36

    #2
    Maybe sed (the stream editor) is what you are looking for?

    man sed

    should give you food for thought!

    hth,
    -cybervegan

    Comment

    • Motoma
      Recognized Expert Specialist
      • Jan 2007
      • 3236

      #3
      I have posted this link to sed and it's companion tutorial on regular expressions at least 8 times in the past month I have been here.

      Comment

      • arthurzzk
        New Member
        • Feb 2007
        • 8

        #4
        rm out.txt
        sed '4,$d' test.txt >> out.txt
        echo "test line 1" >> out.txt
        echo "test line 2" >> out.txt
        sed -n '5,$p' test.txt >> out.txt
        exit

        this only works for this question

        Comment

        Working...