Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I need to remove portion of text from a very big text file.
The text file is something like that:
Abcdefghijk
LOCK TABLES `core_log` WRITE; <----
(DATA - over 1 Gb of text data)
UNLOCK TABLES; <----
lmnopqrstuvxyz
I need to create a script (Windows or Unix) that remove all content from "LOCK TABLES" to "UNLOCK TABLES;" and preserve rest of file. After the script will run I need to have
Abcdefghijk
lmnopqrstuvxyz
I can save the extracted data in another file or I can overwrite the same file.
Thanks for help.
With GNU sed:
sed -i '/^LOCK TABLES/,/^UNLOCK TABLES/d' file
Output to file:
Abcdefghijk
lmnopqrstuvxyz
This is best done with awk:
$ awk '/^LOCK TABLE/{f=1} /^UNLOCK TABLE/{f=0} f' file
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
So I have one modified html file that has some links in it, and I want to extract them (grep or similar) so I only have links that start with http://* and end with .epub, the extension).
I tried some solutions here on stackoverflow, but none seems to work as I can't seem to extract anything.
How would I go in doing this?
EDIT: The links are laid out on the file like this as well: > http://........epub" class="..."><i but I just want to extract everything between http and .epub, including those 2.
grep -o 'http://[^ "<]*.epub' file.html should do the trick
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
In detail, I have a c++ program which takes runtime input of different parameters. I am creating a shell script to automate my process. But the program needs input to be given in the terminal. How do I send the input value from bash when the terminal prompts to enter the input value?
You can use usual flow (pipelining or redirecting) to feed your program with data
./a.out < myFileWithdata.txt
#or with pipelining
echo "my one line" | ./a.out
Another option is to use "here-document":
./a.out << EOF
My first line!
My second line.
EOF
#more commands
Note: EOF is just a convention, it can be any string that will mark end of data to pass to program.
Another option, to pass one line quickly is "here-string":
./a.out <<< "My data!"
#more commands
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
how to write a cpp program for replace string using only 1 text file
for example if in text file abc.txt
Hello
how are you
good
bye
i want output like
Hello
how are you
bad
bye
all above thing will be done in text file
Pretty easy. Open the file, get the text. Then iterate throw each word and ask the user if he/she wants to change that word. If yes, write new word on new file. If not, write old word on new file.
Now you just need to translate that to c++
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
How can I change a number on a line in a file using a unix tool like awk or sed?
I want to change the line 3 in my example file to the number 1-10 using a shell script. I think I need to use regex to recognize the digit but I'm not sure how to do this, or to allow multiple digits (like 10).
Example file:
/examples/are/hard so/hard/1
Shell script so far:
for i in {1..3};
do
sed 's|/examples/are/hard so/hard/7 | /examples/are/hard so/hard/'"$i" ex_file
cat ex_file
done
Desired output:
/examples/are/hard so/hard/1
/examples/are/hard so/hard/2
/examples/are/hard so/hard/3
What you've run isn't a valid sed command. If you're trying to do a substitution, that's s/search/replace/flags.
I imagine you meant:
sed 's/here\/is the number\/to\/change 3/here\/is the number\/to\/change '"$i"'/' ex_file
Note that we temporarily break out of single quote. Inside of single quotes, variable aren't interpolated. We swap the double quotes, bring in $i, then return to single quotes to finish the command.
P.S. You also don't have to use / as your delimiter.
sed 's|here/is the number/to/change 3|here/is the number/to/change '"$i"'|' ex_file
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I have an access log that was written with nginx and lua code.
It is url encoded and those some characters are written in the format of \xHexCode (for example, double quotes are written as \x22).
I would like to run awk or perl or other fast script to replace it back.
You can use gnu-awk like this:
str='\x22 \x41 written as \x22).'
awk -v RS='\\\\x[0-9]+' 'RT{ORS=sprintf("%c", strtonum("0" substr(RT, 2)))} 1' <<< "$str"
" A written as ").
This is how it is working:
Using RS='\\\\x[0-9]+' we're separating custom record separator for each of those \xNN numbers.
substr(RT, 2) takes x41 from \x41
strtonum("0" substr(RT, 2)) adds 0 to make it 0x41 and returns ascii code 65.
printf "%c" prints equivalent ascii character A from 65.
ORS=... sets output record separator same as the return value of sprintf.