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

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.

Related

GREP or Regex Search unique characters with a particular series [closed]

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
I am novice,I want search a huge file using grep or regex which has list of Unique Id's.
Example file:
/icon_edit.png\" \/><\/a> AP-28992 : ABCD-1103_01 [v1]","2","2012-10-27 18:40:47","2012-01-04 13:22:41"],
["shawn","extra\/fax","<!-- 0000000000 --><a href=\"javascript:openTCEditWindow(0000,000);\"><img title=\"
TSD\" src=\"gui\/themes\/default\/images\/icon_edit.png\" \/><\/a> AP-28993 : ABCD-1103_02
[v1]","2","2012-10-27 18:40:47","2012-01-04 13:22:41"],
["shawn","extra\/traax","<!-- 0000000000 --> ABCD_110_01
Should be filtered uniquely below like:
ABCD-1103
ABCD-110
I guess ABCD-110 is your input pattern and space is delimiter
so if your input file viz. abc.txt is like (i have modified the last line)
$cat abc.txt
/icon_edit.png\" \/><\/a> AP-28992 : ABCD-1103_01 [v1]","2","2012-10-27
18:40:47","2012-01-04 13:22:41"],
["shawn","extra\/fax","<!-- 0000000000 --><a
href=\"javascript:openTCEditWindow(0000,000);\"><img title=\"
TSD\" src=\"gui\/themes\/default\/images\/icon_edit.png\" \/><\/a> AP-28993 :
ABCD-1103_02
[v1]","2","2012-10-27 18:40:47","2012-01-04 13:22:41"],
["shawn","extra\/traax","<!-- 0000000000 --> ABCD-110_01
Then the following works:
$cat abc.txt | grep -ow "ABCD-110.*" | awk '{print $1}'
ABCD-1103_01
ABCD-1103_02
ABCD-110_01

Shell script to capture the updated part 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 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

ubuntu linux sed affects file properties? [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 5 years ago.
Improve this question
I have a text file of 75000 items, 2 lines for each item. line 1 has an identifier, line 2 a text string.
I need to remove 130 items, random identifiers that I have in a list or can put in a file.
I can carry out the removal for one item, but not for more than one.
I tried piping the identifiers and get an empty output file.
I tried repeated commands of sed -e 'expression' inputfile > outfile. This works, but requires a new output file that then becomes the inputfile for the next iteration and so on. this might be the last resort.
I tried sed -i in iteration; this crashes and the error is that there is no file by the name of the inputfile. Which is clearly not the case, as I can see it, ls it and grep the number of identifiers in it. Only sed can't seem to read it.
I even found a python/biopython script online for this exact problem, it is very simple and does not give error messages, but it also removes only the first item.
I think it has something to do with file properties/temporary files that don't really exist (?).
I am using Ubuntu 12.04 'Precise'
How can I get around this issue?
quick and dirty (no check if modification file is created, ...)
sed
Assuming there is no special meta character in your pattern list
sed 's#.*#/&/{N;d;}#' YourListToExclude > /tmp/exclude.sed
sed -f /tmp/exclude.sed YourDataFile > /tmp/YourDataFile.tmp
mv /tmp/YourDataFile.tmp YourDataFile
rm /tmp/exclude.sed
awk
awk 'FNR==NR{ex=(ex==""?"":ex"|")$0;next}$0!~ex{print;getline;print;next}{getline}' YourListToExclude YourDataFile > /tmp/YourDataFile.tmp
mv /tmp/YourDataFile.tmp YourDataFile

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.

Remove the comma on at the end of every 4th line [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 7 years ago.
Improve this question
Her is a example of the output. I need to remove the comma at the end of every fourth line.
"tester1",
"SERVICE_TICKET_CREATED",
"Thu Mar 19 23:27:57 UTC 2015",
"111.111.11.1"
"tester1",
"SERVICE_TICKET_CREATED",
"Fri Mar 20 00:31:59 UTC 2015",
"111.111.11.1"
What I am trying to do is
"tester1",
"SERVICE_TICKET_CREATED",
"Thu Mar 19 23:27:57 UTC 2015",
"111.111.11.1"
"tester1",
"SERVICE_TICKET_CREATED",
"Fri Mar 20 00:31:59 UTC 2015",
"111.111.11.1"
With GNU sed:
sed '4~4 s/,$//' filename
I have to point out, though, that in your example output there's no comma at the end of every fourth line.
This should work for you, since the question is tagged "linux" and Linux very nearly always comes with GNU sed. For the sake of completeness: with BSD sed (as found on Mac OS X and *BSD), the 4~4 pattern does not work (it is a GNU extension). There you could do something like
sed 'n;n;n;s/,$//' filename
...which fetches and prints three extra lines every time and removes the comma at the end of the fourth (unless the end of the input was reached before a fourth line could be fetched).
Alternatively, with awk you could use
awk 'NR % 4 == 0 { sub(/,$/, "") } 1' filename

Resources