views:

42

answers:

4

So i have a 1 long line with characters, for example numbers[1-1024] in one line(no "\n", "\t" and "\b"):

1 2 3 4 5 6 7 8 9 10 11 ... 1024

How do i extract and print characters for example exactly 55 characters after 46? So output would be:

47 48 49 ... 101

Thanks.

+1  A: 

You can use the cut utility. For your example, the following command will work.

cut -f 47-101 -d " " file_with_long_line

You can also specify byte or character positions, or change the delimiter string, depending on your input.

Carl Norum
Thanks, but the problem is that this is a huge sql file, and idunno the exact character sequente, i only know a specific string "Galeon-2b" and only idea to get to stdout it's SQL records - is to grep out spesific character/byte range after field "Galeon-2b". :( I dont want to use some special hexedit or forensic stuff, only the power of unix command line. :|
rufus28
@rufus28, that's not what you asked in your question, though.... Why can't you just `grep` for `Galeon-2b` and then do a `cut` on that?
Carl Norum
Yes Carl, i just make that simple exaple for better understanding. I tried with grep but as SQL dump line is so long, grep split this line incorretly, so it is useful only multiple line files or pipes. But i solved the problem. "cat backup.sql | tr -s ")" "\n" | grep Galeon-2b | head -n1"
rufus28
A: 

Why not use cut?

cut -d ' ' -f 46-101
Miguel Ventura
A: 

If you really want to use awk instead of cut, you could set RS=" ", and process relatively normally from there, with each number as a separate record, just like it was on a line by itself.

Jerry Coffin
+1  A: 

This looks for the string "Galeon-2b" and outputs the next 55 characters.

sed -n 's/.*Galeon-2b\(.\{55\}\).*/\1/p' backup.sql
Dennis Williamson