Add a different string in the beginning of each line [closed]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












So I have a txt with some numbers inside and I want to add a string before those numbers, but not the same string in every line. So for example I have:



49.950
38.654
104.138
168.171
100.586


and I want to add before them the words nick, george, james so the result will be



www.abc.com 49.950
www.facebook.com 38.654
www.youtube.com 104.138
www.google.com 168.171
www.twitch.com 100.586


How am I gonna do that?



while read -r line; do x="$line"
if [ "$line" == "www.abc.com" ]; then
ping -c 4 www.abc.com | tail -1 | awk 'print $4' | cut -d '/' -f 2 > results
fi
if [ "$line" == "www.facebook.com" ]; then
ping -c 4 www.facebook.com | tail -1 | awk 'print $4' | cut -d '/' -f 2 >> results
fi
if [ "$line" == "www.youtube.com" ]; then
ping -c 4 www.youtube.com | tail -1 | awk 'print $4' | cut -d '/' -f 2 >> results
fi
if [ "$line" == "www.google.com" ]; then
ping -c 4 www.google.com | tail -1 | awk 'print $4' | cut -d '/' -f 2 >> results
fi
if [ "$line" == "www.twich.com" ]; then
ping -c 4 www.twitch.com | tail -1 | awk 'print $4' | cut -d '/' -f 2 >>results
fi
done <urls






share|improve this question














closed as unclear what you're asking by G-Man, Stephen Rauch, Sparhawk, jimmij, Shadur Nov 20 '17 at 9:28


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.










  • 1




    what if there would be more that 3 numbers?
    – RomanPerekhrest
    Nov 18 '17 at 21:22










  • I have a fixed amount of numbers, they are 5. Actually i'm reading from a txt of 5 urls and I ping every url 4 times, i take the average time of each url and add it to a new txt. So i'm having 5 lines of the 5 average times and i just need to add in front of them the equivalent urls.
    – Georgio3
    Nov 18 '17 at 21:23






  • 1




    update your question with those 5 numbers and respective names/URLs. Also, it's good to post your current code
    – RomanPerekhrest
    Nov 18 '17 at 21:24











  • So, you just want merge two files, line by line? Then, paste -d' ' first.txt second.txt would be enough.
    – MiniMax
    Nov 18 '17 at 21:29






  • 3




    The result you wrote doesn't match the description right before it. You mention names that do not appear on the example output.
    – Zip
    Nov 18 '17 at 21:30














up vote
1
down vote

favorite












So I have a txt with some numbers inside and I want to add a string before those numbers, but not the same string in every line. So for example I have:



49.950
38.654
104.138
168.171
100.586


and I want to add before them the words nick, george, james so the result will be



www.abc.com 49.950
www.facebook.com 38.654
www.youtube.com 104.138
www.google.com 168.171
www.twitch.com 100.586


How am I gonna do that?



while read -r line; do x="$line"
if [ "$line" == "www.abc.com" ]; then
ping -c 4 www.abc.com | tail -1 | awk 'print $4' | cut -d '/' -f 2 > results
fi
if [ "$line" == "www.facebook.com" ]; then
ping -c 4 www.facebook.com | tail -1 | awk 'print $4' | cut -d '/' -f 2 >> results
fi
if [ "$line" == "www.youtube.com" ]; then
ping -c 4 www.youtube.com | tail -1 | awk 'print $4' | cut -d '/' -f 2 >> results
fi
if [ "$line" == "www.google.com" ]; then
ping -c 4 www.google.com | tail -1 | awk 'print $4' | cut -d '/' -f 2 >> results
fi
if [ "$line" == "www.twich.com" ]; then
ping -c 4 www.twitch.com | tail -1 | awk 'print $4' | cut -d '/' -f 2 >>results
fi
done <urls






share|improve this question














closed as unclear what you're asking by G-Man, Stephen Rauch, Sparhawk, jimmij, Shadur Nov 20 '17 at 9:28


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.










  • 1




    what if there would be more that 3 numbers?
    – RomanPerekhrest
    Nov 18 '17 at 21:22










  • I have a fixed amount of numbers, they are 5. Actually i'm reading from a txt of 5 urls and I ping every url 4 times, i take the average time of each url and add it to a new txt. So i'm having 5 lines of the 5 average times and i just need to add in front of them the equivalent urls.
    – Georgio3
    Nov 18 '17 at 21:23






  • 1




    update your question with those 5 numbers and respective names/URLs. Also, it's good to post your current code
    – RomanPerekhrest
    Nov 18 '17 at 21:24











  • So, you just want merge two files, line by line? Then, paste -d' ' first.txt second.txt would be enough.
    – MiniMax
    Nov 18 '17 at 21:29






  • 3




    The result you wrote doesn't match the description right before it. You mention names that do not appear on the example output.
    – Zip
    Nov 18 '17 at 21:30












up vote
1
down vote

favorite









up vote
1
down vote

favorite











So I have a txt with some numbers inside and I want to add a string before those numbers, but not the same string in every line. So for example I have:



49.950
38.654
104.138
168.171
100.586


and I want to add before them the words nick, george, james so the result will be



www.abc.com 49.950
www.facebook.com 38.654
www.youtube.com 104.138
www.google.com 168.171
www.twitch.com 100.586


How am I gonna do that?



while read -r line; do x="$line"
if [ "$line" == "www.abc.com" ]; then
ping -c 4 www.abc.com | tail -1 | awk 'print $4' | cut -d '/' -f 2 > results
fi
if [ "$line" == "www.facebook.com" ]; then
ping -c 4 www.facebook.com | tail -1 | awk 'print $4' | cut -d '/' -f 2 >> results
fi
if [ "$line" == "www.youtube.com" ]; then
ping -c 4 www.youtube.com | tail -1 | awk 'print $4' | cut -d '/' -f 2 >> results
fi
if [ "$line" == "www.google.com" ]; then
ping -c 4 www.google.com | tail -1 | awk 'print $4' | cut -d '/' -f 2 >> results
fi
if [ "$line" == "www.twich.com" ]; then
ping -c 4 www.twitch.com | tail -1 | awk 'print $4' | cut -d '/' -f 2 >>results
fi
done <urls






share|improve this question














So I have a txt with some numbers inside and I want to add a string before those numbers, but not the same string in every line. So for example I have:



49.950
38.654
104.138
168.171
100.586


and I want to add before them the words nick, george, james so the result will be



www.abc.com 49.950
www.facebook.com 38.654
www.youtube.com 104.138
www.google.com 168.171
www.twitch.com 100.586


How am I gonna do that?



while read -r line; do x="$line"
if [ "$line" == "www.abc.com" ]; then
ping -c 4 www.abc.com | tail -1 | awk 'print $4' | cut -d '/' -f 2 > results
fi
if [ "$line" == "www.facebook.com" ]; then
ping -c 4 www.facebook.com | tail -1 | awk 'print $4' | cut -d '/' -f 2 >> results
fi
if [ "$line" == "www.youtube.com" ]; then
ping -c 4 www.youtube.com | tail -1 | awk 'print $4' | cut -d '/' -f 2 >> results
fi
if [ "$line" == "www.google.com" ]; then
ping -c 4 www.google.com | tail -1 | awk 'print $4' | cut -d '/' -f 2 >> results
fi
if [ "$line" == "www.twich.com" ]; then
ping -c 4 www.twitch.com | tail -1 | awk 'print $4' | cut -d '/' -f 2 >>results
fi
done <urls








share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '17 at 14:52









dessert

1,013321




1,013321










asked Nov 18 '17 at 21:21









Georgio3

83




83




closed as unclear what you're asking by G-Man, Stephen Rauch, Sparhawk, jimmij, Shadur Nov 20 '17 at 9:28


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.






closed as unclear what you're asking by G-Man, Stephen Rauch, Sparhawk, jimmij, Shadur Nov 20 '17 at 9:28


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









  • 1




    what if there would be more that 3 numbers?
    – RomanPerekhrest
    Nov 18 '17 at 21:22










  • I have a fixed amount of numbers, they are 5. Actually i'm reading from a txt of 5 urls and I ping every url 4 times, i take the average time of each url and add it to a new txt. So i'm having 5 lines of the 5 average times and i just need to add in front of them the equivalent urls.
    – Georgio3
    Nov 18 '17 at 21:23






  • 1




    update your question with those 5 numbers and respective names/URLs. Also, it's good to post your current code
    – RomanPerekhrest
    Nov 18 '17 at 21:24











  • So, you just want merge two files, line by line? Then, paste -d' ' first.txt second.txt would be enough.
    – MiniMax
    Nov 18 '17 at 21:29






  • 3




    The result you wrote doesn't match the description right before it. You mention names that do not appear on the example output.
    – Zip
    Nov 18 '17 at 21:30












  • 1




    what if there would be more that 3 numbers?
    – RomanPerekhrest
    Nov 18 '17 at 21:22










  • I have a fixed amount of numbers, they are 5. Actually i'm reading from a txt of 5 urls and I ping every url 4 times, i take the average time of each url and add it to a new txt. So i'm having 5 lines of the 5 average times and i just need to add in front of them the equivalent urls.
    – Georgio3
    Nov 18 '17 at 21:23






  • 1




    update your question with those 5 numbers and respective names/URLs. Also, it's good to post your current code
    – RomanPerekhrest
    Nov 18 '17 at 21:24











  • So, you just want merge two files, line by line? Then, paste -d' ' first.txt second.txt would be enough.
    – MiniMax
    Nov 18 '17 at 21:29






  • 3




    The result you wrote doesn't match the description right before it. You mention names that do not appear on the example output.
    – Zip
    Nov 18 '17 at 21:30







1




1




what if there would be more that 3 numbers?
– RomanPerekhrest
Nov 18 '17 at 21:22




what if there would be more that 3 numbers?
– RomanPerekhrest
Nov 18 '17 at 21:22












I have a fixed amount of numbers, they are 5. Actually i'm reading from a txt of 5 urls and I ping every url 4 times, i take the average time of each url and add it to a new txt. So i'm having 5 lines of the 5 average times and i just need to add in front of them the equivalent urls.
– Georgio3
Nov 18 '17 at 21:23




I have a fixed amount of numbers, they are 5. Actually i'm reading from a txt of 5 urls and I ping every url 4 times, i take the average time of each url and add it to a new txt. So i'm having 5 lines of the 5 average times and i just need to add in front of them the equivalent urls.
– Georgio3
Nov 18 '17 at 21:23




1




1




update your question with those 5 numbers and respective names/URLs. Also, it's good to post your current code
– RomanPerekhrest
Nov 18 '17 at 21:24





update your question with those 5 numbers and respective names/URLs. Also, it's good to post your current code
– RomanPerekhrest
Nov 18 '17 at 21:24













So, you just want merge two files, line by line? Then, paste -d' ' first.txt second.txt would be enough.
– MiniMax
Nov 18 '17 at 21:29




So, you just want merge two files, line by line? Then, paste -d' ' first.txt second.txt would be enough.
– MiniMax
Nov 18 '17 at 21:29




3




3




The result you wrote doesn't match the description right before it. You mention names that do not appear on the example output.
– Zip
Nov 18 '17 at 21:30




The result you wrote doesn't match the description right before it. You mention names that do not appear on the example output.
– Zip
Nov 18 '17 at 21:30










1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










Complete bash + awk solution:



while read -r url || [ -n "$url" ]; do 
ping -c4 "$url" | awk -F'/' -v u="$url" 'END print u,$5 '
done <urls > results



The exemplary results file contents (as a result of my local test):



www.abc.com 207.137
www.facebook.com 39.938
www.youtube.com 35.580
www.google.com 128.124
www.twitch.com 144.557





share|improve this answer






















  • This is a complete solution, describes the whole process? From pinging to generating the final txt file?
    – Georgio3
    Nov 18 '17 at 21:38






  • 1




    @Georgio3, you're welcome. As for leaning - bash is pretty useful for System/Unix programming. Anyway, it's your choice
    – RomanPerekhrest
    Nov 18 '17 at 21:48







  • 1




    Java is primarily used these days to develop server software and the vast majority of such software runs on Linux. As a 20-year veteran of primarily Java software development I can tell you that you that there is a very high probability you will need at some familiarity with Linux command line tools, scripting and general systems knowledge (unless you are referring to developing Java desktop applications...a shrinking, niche market if ever there was one).
    – B Layer
    Nov 19 '17 at 5:47







  • 1




    This won't take the last line if it doesn't end with a linebreak. Use while read -r url || [ -n "$url" ]; do …; done <urls instead to be sure.
    – dessert
    Nov 19 '17 at 13:04







  • 1




    You could also just redirect the whole loop's output instead of opening the file multiple times inside the loop: …; done <urls >results
    – dessert
    Nov 19 '17 at 13:12

















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote



accepted










Complete bash + awk solution:



while read -r url || [ -n "$url" ]; do 
ping -c4 "$url" | awk -F'/' -v u="$url" 'END print u,$5 '
done <urls > results



The exemplary results file contents (as a result of my local test):



www.abc.com 207.137
www.facebook.com 39.938
www.youtube.com 35.580
www.google.com 128.124
www.twitch.com 144.557





share|improve this answer






















  • This is a complete solution, describes the whole process? From pinging to generating the final txt file?
    – Georgio3
    Nov 18 '17 at 21:38






  • 1




    @Georgio3, you're welcome. As for leaning - bash is pretty useful for System/Unix programming. Anyway, it's your choice
    – RomanPerekhrest
    Nov 18 '17 at 21:48







  • 1




    Java is primarily used these days to develop server software and the vast majority of such software runs on Linux. As a 20-year veteran of primarily Java software development I can tell you that you that there is a very high probability you will need at some familiarity with Linux command line tools, scripting and general systems knowledge (unless you are referring to developing Java desktop applications...a shrinking, niche market if ever there was one).
    – B Layer
    Nov 19 '17 at 5:47







  • 1




    This won't take the last line if it doesn't end with a linebreak. Use while read -r url || [ -n "$url" ]; do …; done <urls instead to be sure.
    – dessert
    Nov 19 '17 at 13:04







  • 1




    You could also just redirect the whole loop's output instead of opening the file multiple times inside the loop: …; done <urls >results
    – dessert
    Nov 19 '17 at 13:12














up vote
2
down vote



accepted










Complete bash + awk solution:



while read -r url || [ -n "$url" ]; do 
ping -c4 "$url" | awk -F'/' -v u="$url" 'END print u,$5 '
done <urls > results



The exemplary results file contents (as a result of my local test):



www.abc.com 207.137
www.facebook.com 39.938
www.youtube.com 35.580
www.google.com 128.124
www.twitch.com 144.557





share|improve this answer






















  • This is a complete solution, describes the whole process? From pinging to generating the final txt file?
    – Georgio3
    Nov 18 '17 at 21:38






  • 1




    @Georgio3, you're welcome. As for leaning - bash is pretty useful for System/Unix programming. Anyway, it's your choice
    – RomanPerekhrest
    Nov 18 '17 at 21:48







  • 1




    Java is primarily used these days to develop server software and the vast majority of such software runs on Linux. As a 20-year veteran of primarily Java software development I can tell you that you that there is a very high probability you will need at some familiarity with Linux command line tools, scripting and general systems knowledge (unless you are referring to developing Java desktop applications...a shrinking, niche market if ever there was one).
    – B Layer
    Nov 19 '17 at 5:47







  • 1




    This won't take the last line if it doesn't end with a linebreak. Use while read -r url || [ -n "$url" ]; do …; done <urls instead to be sure.
    – dessert
    Nov 19 '17 at 13:04







  • 1




    You could also just redirect the whole loop's output instead of opening the file multiple times inside the loop: …; done <urls >results
    – dessert
    Nov 19 '17 at 13:12












up vote
2
down vote



accepted







up vote
2
down vote



accepted






Complete bash + awk solution:



while read -r url || [ -n "$url" ]; do 
ping -c4 "$url" | awk -F'/' -v u="$url" 'END print u,$5 '
done <urls > results



The exemplary results file contents (as a result of my local test):



www.abc.com 207.137
www.facebook.com 39.938
www.youtube.com 35.580
www.google.com 128.124
www.twitch.com 144.557





share|improve this answer














Complete bash + awk solution:



while read -r url || [ -n "$url" ]; do 
ping -c4 "$url" | awk -F'/' -v u="$url" 'END print u,$5 '
done <urls > results



The exemplary results file contents (as a result of my local test):



www.abc.com 207.137
www.facebook.com 39.938
www.youtube.com 35.580
www.google.com 128.124
www.twitch.com 144.557






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 19 '17 at 16:38

























answered Nov 18 '17 at 21:37









RomanPerekhrest

22.4k12145




22.4k12145











  • This is a complete solution, describes the whole process? From pinging to generating the final txt file?
    – Georgio3
    Nov 18 '17 at 21:38






  • 1




    @Georgio3, you're welcome. As for leaning - bash is pretty useful for System/Unix programming. Anyway, it's your choice
    – RomanPerekhrest
    Nov 18 '17 at 21:48







  • 1




    Java is primarily used these days to develop server software and the vast majority of such software runs on Linux. As a 20-year veteran of primarily Java software development I can tell you that you that there is a very high probability you will need at some familiarity with Linux command line tools, scripting and general systems knowledge (unless you are referring to developing Java desktop applications...a shrinking, niche market if ever there was one).
    – B Layer
    Nov 19 '17 at 5:47







  • 1




    This won't take the last line if it doesn't end with a linebreak. Use while read -r url || [ -n "$url" ]; do …; done <urls instead to be sure.
    – dessert
    Nov 19 '17 at 13:04







  • 1




    You could also just redirect the whole loop's output instead of opening the file multiple times inside the loop: …; done <urls >results
    – dessert
    Nov 19 '17 at 13:12
















  • This is a complete solution, describes the whole process? From pinging to generating the final txt file?
    – Georgio3
    Nov 18 '17 at 21:38






  • 1




    @Georgio3, you're welcome. As for leaning - bash is pretty useful for System/Unix programming. Anyway, it's your choice
    – RomanPerekhrest
    Nov 18 '17 at 21:48







  • 1




    Java is primarily used these days to develop server software and the vast majority of such software runs on Linux. As a 20-year veteran of primarily Java software development I can tell you that you that there is a very high probability you will need at some familiarity with Linux command line tools, scripting and general systems knowledge (unless you are referring to developing Java desktop applications...a shrinking, niche market if ever there was one).
    – B Layer
    Nov 19 '17 at 5:47







  • 1




    This won't take the last line if it doesn't end with a linebreak. Use while read -r url || [ -n "$url" ]; do …; done <urls instead to be sure.
    – dessert
    Nov 19 '17 at 13:04







  • 1




    You could also just redirect the whole loop's output instead of opening the file multiple times inside the loop: …; done <urls >results
    – dessert
    Nov 19 '17 at 13:12















This is a complete solution, describes the whole process? From pinging to generating the final txt file?
– Georgio3
Nov 18 '17 at 21:38




This is a complete solution, describes the whole process? From pinging to generating the final txt file?
– Georgio3
Nov 18 '17 at 21:38




1




1




@Georgio3, you're welcome. As for leaning - bash is pretty useful for System/Unix programming. Anyway, it's your choice
– RomanPerekhrest
Nov 18 '17 at 21:48





@Georgio3, you're welcome. As for leaning - bash is pretty useful for System/Unix programming. Anyway, it's your choice
– RomanPerekhrest
Nov 18 '17 at 21:48





1




1




Java is primarily used these days to develop server software and the vast majority of such software runs on Linux. As a 20-year veteran of primarily Java software development I can tell you that you that there is a very high probability you will need at some familiarity with Linux command line tools, scripting and general systems knowledge (unless you are referring to developing Java desktop applications...a shrinking, niche market if ever there was one).
– B Layer
Nov 19 '17 at 5:47





Java is primarily used these days to develop server software and the vast majority of such software runs on Linux. As a 20-year veteran of primarily Java software development I can tell you that you that there is a very high probability you will need at some familiarity with Linux command line tools, scripting and general systems knowledge (unless you are referring to developing Java desktop applications...a shrinking, niche market if ever there was one).
– B Layer
Nov 19 '17 at 5:47





1




1




This won't take the last line if it doesn't end with a linebreak. Use while read -r url || [ -n "$url" ]; do …; done <urls instead to be sure.
– dessert
Nov 19 '17 at 13:04





This won't take the last line if it doesn't end with a linebreak. Use while read -r url || [ -n "$url" ]; do …; done <urls instead to be sure.
– dessert
Nov 19 '17 at 13:04





1




1




You could also just redirect the whole loop's output instead of opening the file multiple times inside the loop: …; done <urls >results
– dessert
Nov 19 '17 at 13:12




You could also just redirect the whole loop's output instead of opening the file multiple times inside the loop: …; done <urls >results
– dessert
Nov 19 '17 at 13:12


Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?