0

I have a text file which contains a list of values:

ASDSAV
ASDSAD
ASDFSA

and need to get

ASDSAV        7
ASDSAD        7
ASDFSA        7

i.e. join it with a file that is just one column of 7s (which can be easily achieved with paste)

7
7
7

Is there easy command to create this file of 7s?

1
  • I never really used sed or awk... Commented Feb 7, 2013 at 2:48

5 Answers 5

2
awk '{print $0, "7"} ' inputfile > newfile

There is no need for a separate file of 7's

Sign up to request clarification or add additional context in comments.

Comments

2

The question is actually how to create a file with a list of sevens.

You can use some coreutils:

printf '7\n%.0s' $(seq $(wc -l < file)) > output.txt

or awk:

awk '{ print "7" > "output.txt" }' file

or sed:

sed 's/.*/7/' file > output.txt

1 Comment

touchè i guess we assumed pasting wasn't efficent
1

awk '{print $1 " 7"}' temp.dat; where temp.dat is your original file.

Comments

1

ALMIGHTY SED

sed -e "s/$/7/" f1 > f2 

MAY YOUR AWKS CRUMBLE BEFORE HIS FEET

side note: if u want to tab the 7 out in sed it would be

sed -e "s/$/<ctrl+v><tab>7/" f1 > f2 

Comments

0

The yes command provides an unlimited supply of its argument:

yes 7 | head -n $(wc -l < file.txt) | paste file.txt -

(It's good to know about yes, but in this case it's a bit clunky. paste auto-extends shorter input files with empty lines, and the yes-supplied standard input is infinitely long without the head to limit it.)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.