I'd like to cut a certain range of text (i.e. characters 17-63) repeatedly from a *.txt file, which is several thousand lines long.

One line looks like this:

<script>addRow("monatswerte_RR_00002_19140101_20061231_hist.zip","monatswerte_RR_00002_19140101_20061231_hist.zip",0,"12.3 kB","8/11/15, 5:18:00 PM");</script>

Can anyone suggest how to:

i. Cut this text range?

ii. Append it to another common string?


awk -F\" '{print $2}' all-files.txt > output.txt

Gives me a .txt file named output.txt. I then used

awk '{print "ftp://ftp-server.etc..." $0;}' output.txt > list.txt

To generate the final list of filenames needed for web-scraping.

  • 2
    normal way to cut columns is with cut ... cut -c17-64 file.txt ... does that not work? – Jeff Schaller Feb 1 '16 at 19:14
  • Well, define a column ? Because you have <script>, addRow., parenthesis, </script> stuff like that. What exactly you need to extract in the lines ? What exactly you want to keep ? are you reffering to columns as those coma separated values inside parenthesis ? – Sergiy Kolodyazhnyy Feb 1 '16 at 19:22
  • @Serg I've updated the question for clarity.. – danny_C_O_T_W Feb 1 '16 at 21:37

My first thought was the same as Jeff Schaller's: cut -c 17-64. However that includes the closing quote, so you need cut -c 17-63

If you want the first quoted word and not every word is the same length, you can use awk: awk -F\" '{print $2}' file.txt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.