Shell script to capture the updated part in a file [closed] - linux

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
file 1
23
1030042388
0
1.000000000000000
739203
0.041035795614451
754163
0.010276519532845
827907
0.147827256904898
2961752
0.017365353262416
3006283
The above file gets updated as
file1
23
1030042388
0
1.000000000000000
739203
0.041035795614451
754163
0.007314889610240
130695515
0.010276519532845
827907
0.147827256904898
2961752
0.017365353262416
3006283
0.000185740873681
13483011
0.028083838182834
13497795
0.011287502580049
13512752
0.219960404756292
13512755
Note updation can happen any where in the file, and numbers/lines should not be sorted
i need to capture only the update part in to other file
file 3
0.007314889610240
130695515
0.000185740873681
13483011
0.028083838182834
13497795
0.011287502580049
13512752
0.219960404756292
13512755
Could you please help me in this
Thanks

Using comm:
% comm -13 <(sort f1.txt) <(sort f2.txt)
0.000185740873681
0.007314889610240
0.011287502580049
0.028083838182834
0.219960404756292
130695515
13483011
13497795
13512752
13512755

Related

Linux get part of line's text if matched string in files [closed]

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 1 year ago.
Improve this question
In Linux, I have a file test.log that is similar to this:
2021/11/18 17:19:18,034 INFO {"queueName":"queue/RequestQueue",{"threadName":"WorkManager(2)-702","correlationID":"b67601e81bfd","requestData":"TYPE_1, REQUEST 1"}
2021/11/18 17:19:18,036 INFO {"queueName":"queue/ResponseQueue","correlationID":"TMYHxIyeYo","responseData":"TYPE_1, RESPONSE 1"}
2021/11/18 17:19:18,038 INFO {"queueName":"queue/RequestQueue",{"threadName":"WorkManager(2)-885","correlationID":"j9BNzbbv3E","requestData":"TYPE_2, REQUEST 2"}
2021/11/18 17:19:19,172 INFO {"queueName":"queue/RequestQueue",{"threadName":"WorkManager(2)-183","correlationID":"d29d2d7cf5a4","requestData":"TYPE_1, REQUEST 3"}
2021/11/18 17:19:20,784 INFO {"queueName":"queue/esbRequestQueue",{"threadName":"WorkManager(2)-762","correlationID":"4235eba2765a","requestData":"TYPE_1, REQUEST 4"}
I want to search through all lines of this file and get the lines that have the string ["requestData":"TYPE_1] and write all of the requestData's content to another file called type_1.txt. Each matching line in the test.log file will be written to one line in the type_1.txt file. Below is my expected result in the type_1.txt file:
TYPE_1, REQUEST 1
TYPE_1, REQUEST 3
TYPE_1, REQUEST 4
My question is are there commands that can do this? I'm new to Linux so please help me with this.
Try this command:
grep -Po '(?<="requestData":")TYPE_1[^"]*' test.log > type_1.txt

Break log files after first occurrence of a string in unix [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
On a Unix server the log file has appended since long and now it size is 42 gb.
I have to check all logs for after the first occurrence of a particular date i.e: Nov 12 , 2018.
I need all logs for the date Nov 12, 2018. What is the best possible way to do it?
Assuming you are looking for Nov 12 , 2018 text in the log file you can use sed to print everything after Nov 12 , 2018 is matched:
sed -ne '/Nov 12 , 2018/,$ p' <path to log file>
If the date is always at the beginning of the line you can use grep with regex to filter out specific lines:
grep -e "^Nov 12 , 2018" <path to log file>
If you only need the logs for that specific date just do:
grep "Nov 12, 2018" file.log
you can do:
grep -e "$Nov 12 , 2018" yourlogfile.txt > filteredlog.txt
make sure you match the date and year correctly.

Changing the date format in a file [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I'm working on redHat linux.
I've a file which looks like :
$vi filename
Jan,1,00:00:01,someone checked your file
Jan,3,09:38:02,applebee
Jan,16,10:20:03, ****************
Jan,18,03:04:03, ***************
I want the output to look like:
2015/01/01,00:00:01,someone checked your file
2015/01/03,3,09:38:02,applebee
2015/01/16,16,10:20:03, ****************
2015/01/18,03:04:03, ***************
Please help me to do this. Thanks
If you have GNU date, try:
$ awk -F, '{cmd="date -d \""$1" "$2"\" +%Y/%m/%d"; cmd|getline d; print d","$3","$4; close(cmd)}' file
2015/01/01,00:00:01,someone checked your file
2015/01/03,09:38:02,applebee
2015/01/16,10:20:03, ****************
2015/01/18,03:04:03, ***************
This approach cannot be used with the BSD (OSX) version of date because it does not support any comparable -d option.
How it works
awk implicitly loops over lines of input, breaking each line into fields.
-F,
This tells awk to use a comma as the field separator
cmd="date -d \""$1" "$2"\" +%Y/%m/%d"
This creates a string variable, cmd, and contains a date command. I am assuming that you have GNU date.
cmd|getline d
This runs the command and captures the output in variable d.
print d","$3","$4
This prints the output that you asked for.
close(cmd)
This closes the command.

Shell variable is being treated as command [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I have written this small script to compare file name with the files in one folder and copy them to another folder if they do not exist in the first one. Please refer code. But for some reason Ubuntu 15.04 is treating my variable as command and giving me following error:
./COPY_FILES.sh: line 8: FILE_EXIST_IN_SUPER_STRING: command not found
while read NAME1
do
FILE_EXIST_IN_SUPER_STRING = 0
while read NAME2
do
if [ "$NAME1" == "$NAME2" ]
then
FILE_EXIST_IN_SUPER_STRING = 1
fi
done < file_superstring.txt
if [ "$FILE_EXIST_IN_SUPER_STRING" == 0 ]
then
cp Master/"$NAME1" Non-SuperString/"$NAME1"
fi
done < Total_files.txt
Third line should have no spaces.
It should be:
FILE_EXIST_IN_SUPER_STRING=0

How to replace a string in a filename [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I'm trying to replace a string in a filename:
Original filename:
gamename games.com.zip
Target filename:
gamename.zip
I'm trying to replace the string games.com with an empty string. gamename is not a constant string it can be anything, but games.com is a constant string.
I'd use
mv "$filename" "${filename/ games.com/}"
This is documented under 'Pattern subsitution' in the 'Bash' man-page
Or http://www.gnu.org/software/bash/manual/bashref.html#Shell-Parameter-Expansion online
Bash parameter expansion will help:
mv "$f" "${f/ games.com}"
Try the following rename command:
$ filename="gamename games.com.zip"
$ rename " games.com" "" "$filename"
Since the name of your zip file has a space you need to make sure you enclose it in double-quotes.

Resources