bash scripting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting bash scripting
# 1  
Old 04-13-2011
bash scripting

Hello everyone!!!! I am new to this forum ...I have a problem. And I thought that you are expert Smilie so you can help me with that... I have a text file with maaany lines. Every line begins with something like that:
<http aksjfskcuhrf kushkfsnus> <http sxnfrksehfsd gsdg r> I don't know if every line has two http beacause the lines are too many but I know that every line has at least two. I would like to remove these https and leave every line with whatever has next. I just want to remove these https from every line.
Also, I would like to choose random 10 lines from the modified file (without the https) and write them in a file.
I would be the happiest person in the world if you could help me with these problems...
thank you in advance!!! Smilie
# 2  
Old 04-13-2011
something like
Code:
sed 's/<http[^>]*>//g' inputfile | tail +$(($RANDOM%$(wc -l <infile | xargs) )) | head >outputfile

This User Gave Thanks to ctsgnb For This Post:
# 3  
Old 04-13-2011
omg!! thank tou very much for the quick answer!!!!
but I have a problem...
no, in each line, I have these:
< < mplamplampla...

---------- Post updated at 06:02 PM ---------- Previous update was at 06:01 PM ----------

I want to have only the: mplamplampla

---------- Post updated at 06:04 PM ---------- Previous update was at 06:02 PM ----------

hmmm I think that I fixed it!! :

I had forgotten the < !!!! :P
# 4  
Old 04-13-2011
Could you please provide an example of input you have,
as well as an example of output you expect ?

(ideally you can upload you file so people can make some test run with your real case and provide a more accurrate help to you.)

---------- Post updated at 01:06 AM ---------- Previous update was at 01:05 AM ----------

... ah ok lol
# 5  
Old 04-13-2011
can i ask one more question??
after the last > my phrases begin after one space sotmething like this:
lalalalalala
I want to have
lalalalalala without a space in front of it

---------- Post updated at 06:08 PM ---------- Previous update was at 06:06 PM ----------

yeeesss I did it!!!
sed 's/<http[^>]*> //g' inputfile
# 6  
Old 04-13-2011
Quote:
Originally Posted by ctsgnb
something like
Code:
sed 's/<http[^>]*>//g' inputfile | tail +$(($RANDOM%$(wc -l <infile | xargs) )) | head >outputfile

I'm curious. Why pipe into xargs?
# 7  
Old 04-13-2011
You want to remove whitespace at beginning of a line ?
Code:
sed 's/^  *//' inputfile >outputfile

You can gather it into one sed for example:
Code:
sed 's/<http[^>]*>//g;s/^  *//' inputfile >outputfile

---------- Post updated at 01:15 AM ---------- Previous update was at 01:10 AM ----------

@alister :

Code:
$ wc -l <myt
       2
$ wc -l <myt | xargs
2

But i suppose if you point it out to me, it just means that my xargs is useless because the simple calculation and expansion will remove the leading tab anyway ...

---------- Post updated at 01:23 AM ---------- Previous update was at 01:15 AM ----------

by the way, my code contains an error of logic :
if a file contains n lines, my random stuff could bring a number which is n-1 or n-2 ... so there are only 1 or 2 ... lines to tail (so my code would need some enforcement to make sure we really get at least 10 lines).
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Bash Scripting

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Try running 'phone4 xyz' and see what happens. Modify your program so that if no matching name is found, an... (1 Reply)
Discussion started by: OmgHaxor
1 Replies

2. Shell Programming and Scripting

bash scripting

same script: 1- i am using grep to find a string called: tinker panic 0 in a file /etc/ntp.conf if the string is not there, i want to add the strings in /etc/ntp.conf file in the first line of the file. if not do nothing or exit. 2- also i want to add # in front of the following lines in... (0 Replies)
Discussion started by: lamoul
0 Replies

3. Shell Programming and Scripting

bash scripting help

Hi Guys i have a <script?> that spits out the location of each printer using snpget here is the code for i in `sed -n '/Start Printer/,/End Printer/p' /hosts/blah/etc/dhcp/hosts.conf | awk '!/^#/ {print $2}' | egrep -v \... (2 Replies)
Discussion started by: ab52
2 Replies

4. Shell Programming and Scripting

Bash scripting

Try to imagine a flag: nnnnx nnnxx nnxxx nxxxx now imagine how it will output: 4 times the "n"and 1 times "x" 3 times "n"and" 2 times" x " .. etc. .. rhombus is the same only instead of "n" is there gap "and " x "is a few times to form the correct shape Can you help... (3 Replies)
Discussion started by: krcek12
3 Replies

5. Shell Programming and Scripting

bash scripting help

have this code but when i run it i get this error ./pulse: line 2: and here is the code #!/bin/bash if ; then pulseaudio -k; fi what am i doing wrong thanks Adam (5 Replies)
Discussion started by: ab52
5 Replies

6. Shell Programming and Scripting

please help with Bash Scripting????

Hi, can anyone help me with my scrip please. I wanted do following tasks: 1. List all the directory 2. A STDIN to ask user to enter a directory name from listed directories 3. command to check if the directory exists( or a command to validate if the user entered a valid directory name) ... (2 Replies)
Discussion started by: eminjan
2 Replies

7. Shell Programming and Scripting

bash scripting help!!

Hi, can anyone help me with my scrip please. I wanted do following tasks: 1. List all the directory 2. A STDIN to ask user to enter a directory name from listed directories 3. command to check if the directory exists( or a command to validate if the user entered a valid directory name)... (3 Replies)
Discussion started by: eminjan
3 Replies

8. UNIX for Dummies Questions & Answers

Should I do a bash scripting course?!

Hello, I'm confused (oh, yes). I'm running Linux at work. When I type 'echo $SHELL' I am told that I'm running tcsh. In /bin I note that both tcsh and bash are listed. Question 1: Can I swap to run bash rather than tcsh and, if so, how will this affect my system? Is there any advantage to... (6 Replies)
Discussion started by: macpete
6 Replies

9. Shell Programming and Scripting

Bash Scripting

Hello there peeps: There is a little piece of bash shell scripting problem i have, which i was hoping you could help me with. #!/bin/bash stored_word() { case $(( $$ % 8 )) in 0 ) echo "energy";; 1 ) echo "touch";; 2 ) echo "climbing";; 3 ) echo... (3 Replies)
Discussion started by: keyvan
3 Replies
Login or Register to Ask a Question