0

I Have a huge file (50000 rows) looks like :

input.txt:

123315334262625363534
265343426272282827262
224343536625242536363
635352627273635373732
363353533637383838327
635342422325337474524

I want to add row numbers as the first column at the beginning of the file while each number repeated two times:

1 123315334262625363534
1 265343426272282827262
2 224343536625242536363
2 635352627273635373732
3 363353533637383838327
3 635342422325337474524

any suggestion please?

3 Answers 3

1

With awk:

awk '{getline l; printf "%d %s\n%d %s\n", ++i, $0, i, l}' <in >out
2
  • thanks, if I want the row number do not be repeated then how should I change this? I mean if I want it to be like 1 2 3 ... Commented Oct 5, 2015 at 19:02
  • @zara: Just awk '{print FNR, $0}' <in >out. Commented Oct 5, 2015 at 19:03
0

Other awk

awk '{print ++count, $0}NR%2{count--}' <in >out

sed + nl

sed 'N;s/\n/@/' <in |
nl |
sed 's/\(\(^\s*[0-9]*\s*\).*\)@/\1\n\2/' >out
0
perl -pe 'printf "%d ", .5+$./2'

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.