-2

I want to copy the number in a particular line from one text file and paste that number to other text file, how to do this using shell scripting. For example in file1 I have a line

Total Time: 2.3456.

I want to copy 2.3456 and paste into another file. The line number for this line is not always the same.

  • How will you choice the line in which you want to paste a number? – Costas Sep 2 '15 at 8:49
0

try

 awk '/Total Time/ {print $3} ' source_file > dest_file
  • you can use >> to append

if there are many line with Total Time, you can narrow using

awk '$1 == "Total" && $2 == "Time:"  {print $3}  ' source_file > dest_file
  • $1$2 == "TotalTime:" seems shorter – Costas Sep 2 '15 at 12:39
  • unless there is a line like "T otaltime:" ... – Archemar Sep 2 '15 at 12:41
  • Are you serious? Do you beleve in it? – Costas Sep 2 '15 at 12:45

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.