Sponsored Content
Top Forums Shell Programming and Scripting Extract the lines from input file Post 302436053 by sandy1028 on Friday 9th of July 2010 08:02:35 AM
Old 07-09-2010
sed -n '/[5\/Jul\/2010:06:00:00/,/[6\/Jul\/2010:09:00:00/p' soredfile.tsv > output
sed: -e expression #1, char 50: unterminated address regex

Code:
b    [5/Jul/2010:07:00:10
a    [5/Jul/2010:06:00:09
b    [5/Jul/2010:07:00:10
c    [5/Jul/2010:07:10:16
d    [5/Jul/2010:08:00:10
e    [5/Jul/2010:09:00:10
f    [5/Jul/2010:10:00:10
h    [5/Jul/2010:11:00:10
i    [5/Jul/2010:12:00:20
j    [5/Jul/2010:13:00:10
k    [5/Jul/2010:14:00:10
l    [5/Jul/2010:15:00:30
m    [5/Jul/2010:16:00:10
n    [5/Jul/2010:17:00:10
o    [5/Jul/2010:18:00:10
p    [5/Jul/2010:19:00:40
q    [5/Jul/2010:20:00:10
a    [5/Jul/2010:21:00:10
b    [5/Jul/2010:22:00:50
v    [5/Jul/2010:23:00:20
g    [6/Jul/2010:01:00:10
k    [6/Jul/2010:02:00:10
i    [6/Jul/2010:03:00:14
j    [6/Jul/2010:04:00:10
k    [6/Jul/2010:05:00:18
l    [6/Jul/2010:06:00:10
m    [6/Jul/2010:07:00:10
n    [6/Jul/2010:08:00:19
n    [6/Jul/2010:09:00:10



---------- Post updated at 04:47 AM ---------- Previous update was at 04:13 AM ----------

Thanks, this worked fine.

Another problem is

I have the date in the variable as 20100705 and 20100706.

How to convert the date as 5/Jul/2010 and 6/Jul/2010 and pass the dates as a variable in the sed command


sort -k2 tmp.tsv | sed -n '/\[5\/Jul\/2010:06:00:00/,/\[6\/Jul\/2010:09:00:00/p' > tab.tsv

---------- Post updated at 07:02 AM ---------- Previous update was at 04:47 AM ----------

How to pass the variable
$date1
$date2
where $date1 is ' 6\/Jul\/2010'
and $date2 is '7\/Jul\/2010'
sort -k4 tmp.tsv | sed -n '/\[$date1:06:00:00/,/\[$date2:09:00:00/p' > tab.tsv
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to extract a sequence of n lines from a file

Hi I want to be able to extract a sequence of n lines from a file. ideas, commands and suggestions would be highly appreciated. Thanks (4 Replies)
Discussion started by: 0ktalmagik
4 Replies

2. Shell Programming and Scripting

extract particular lines from text file

I have two files file A which have a number in every row and file B which contains few hundred thousand rows with about 300 characters in each row (csv) What I need is to extract whole rows from B file (only these which numbers are indicated in A file) I also need to use cygwin. Any... (7 Replies)
Discussion started by: gunio
7 Replies

3. Shell Programming and Scripting

how do i join two lines from a input file

HI all, i have a input file,i have to join 2nd line into firstline and 4th line into 2nd line and so on.. for this we also consider odd no. of line.It's operate on original input file but output file should temp file. like .. filename=cdr.cfg line1 line2 line3 line4Desired output should be... (9 Replies)
Discussion started by: suryanarayan
9 Replies

4. Shell Programming and Scripting

input text at certain lines of a file

Hi, I have an xml file which will be edited by the user. I would like to get input from user and insert that at line 40 of the xml file. PLease can some one help me to know how to insert the text at specified line using shell script. (6 Replies)
Discussion started by: sunrexstar
6 Replies

5. Shell Programming and Scripting

Extract some lines from one file and add those lines to current file

hi, i have two files. file1.sh echo "unix" echo "linux" file2.sh echo "unix linux forums" now the output i need is $./file2.sh unix linux forums (3 Replies)
Discussion started by: snreddy_gopu
3 Replies

6. Shell Programming and Scripting

Extract particular lines from a file

Hi all, I have a file with many records with information as given below ID A16L2_HUMAN Reviewed; 619 AA. AC Q8NAA4; A5PL30; B2RPK5; Q658V4; Q6PID3; Q8NBG0; DT 20-MAY-2008, integrated into UniProtKB/Swiss-Prot. DT 20-MAY-2008, sequence version 2. DT ... (1 Reply)
Discussion started by: kaav06
1 Replies

7. Shell Programming and Scripting

How to extract certain lines from a file?

Hi guys I have a several thousands line file in the following format: n817 -------------------------------------------------- n842 -------------------------------------------------- n877 -------------------------------------------------- n513 /bb/data/rmt2db.lrl:JBSKDB 31915 75... (4 Replies)
Discussion started by: aoussenko
4 Replies

8. Shell Programming and Scripting

Removing multiple lines from input file, if multiple lines match a pattern.

GM, I have an issue at work, which requires a simple solution. But, after multiple attempts, I have not been able to hit on the code needed. I am assuming that sed, awk or even perl could do what I need. I have an application that adds extra blank page feeds, for multiple reports, when... (7 Replies)
Discussion started by: jxfish2
7 Replies

9. Shell Programming and Scripting

Extract lines from a file

Hi all; Here is my file which contains a list of files (recent versions of files are in red). This file is dynamic, files versions can change at any time (versions can increment) filename ------------------------------------------------------- ... (8 Replies)
Discussion started by: chercheur111
8 Replies

10. Shell Programming and Scripting

Bash to extract file prefix and from input to use in output

In the bash below which does execute I am trying to extract the contents of ${id} is 1234, as ${id} stores the variable that changes each time. After the path is removed the contents of ${id} are stored in pref, so they can be used in the output. Currently I am not able to extract the 1234 in the... (6 Replies)
Discussion started by: cmccabe
6 Replies
AC(1)							      General Commands Manual							     AC(1)

NAME
ac - print statistics about users' connect time SYNOPSIS
ac [ -d | --daily-totals ] [ -y | --print-year ] [ -p | --individual-totals ] [ people ] [ -f | --file filename ] [ -a | --all-days ] [ --complain ] [ --reboots ] [ --supplants ] [ --timewarps ] [ --compatibility ] [ --tw-leniency num ] [ --tw-suspicious num ] [ -z | --print-zeros ] [ --debug ] [ -V | --version ] [ -h | --help ] DESCRIPTION
ac prints out a report of connect time (in hours) based on the logins/logouts in the current wtmp file. A total is also printed out. The accounting file wtmp is maintained by init(8) and login(1). Neither ac nor login creates the wtmp if it doesn't exist, no accounting is done. To begin accounting, create the file with a length of zero. NOTE: The wtmp file can get really big, really fast. You might want to trim it every once and a while. GNU ac works nearly the same u*x ac, though it's a little smarter in several ways. You should therefore expect differences in the output of GNU ac and the output of ac's on other systems. Use the command info accounting to get additional information. OPTIONS
-d, --daily-totals Print totals for each day rather than just one big total at the end. The output looks like this: Jul 3 total 1.17 Jul 4 total 2.10 Jul 5 total 8.23 Jul 6 total 2.10 Jul 7 total 0.30 -p, --individual-totals Print time totals for each user in addition to the usual everything-lumped-into-one value. It looks like: bob 8.06 goff 0.60 maley 7.37 root 0.12 total 16.15 people Print out the sum total of the connect time used by all of the users included in people. Note that people is a space separated list of valid user names; wildcards are not allowed. -f, --file filename Read from the file filename instead of the system's wtmp file. --complain When the wtmp file has a problem (a time-warp, missing record, or whatever), print out an appropriate error. --reboots Reboot records are NOT written at the time of a reboot, but when the system restarts; therefore, it is impossible to know exactly when the reboot occurred. Users may have been logged into the system at the time of the reboot, and many ac's automatically count the time between the login and the reboot record against the user (even though all of that time shouldn't be, perhaps, if the system is down for a long time, for instance). If you want to count this time, include the flag. *For vanilla ac compatibility, include this flag.* --supplants Sometimes, a logout record is not written for a specific terminal, so the time that the last user accrued cannot be calculated. If you want to include the time from the user's login to the next login on the terminal (though probably incorrect), include this you want to include the time from the user's login to the next login on the terminal (though probably incorrect), include this flag. *For vanilla ac compatibility, include this flag.* --timewarps Sometimes, entries in a wtmp file will suddenly jump back into the past without a clock change record occurring. It is impossible to know how long a user was logged in when this occurs. If you want to count the time between the login and the time warp against the user, include this flag. *For vanilla ac compatibility, include this flag.* --compatibility This is shorthand for typing out the three above options. -a, --all-days If we're printing daily totals, print a record for every day instead of skipping intervening days where there is no login activity. Without this flag, time accrued during those intervening days gets listed under the next day where there is login activity. --tw-leniency num Set the time warp leniency to num seconds. Records in wtmp files might be slightly out of order (most notably when two logins occur within a one-second period - the second one gets written first). By default, this value is set to 60. If the program notices this problem, time is not assigned to users unless the --timewarps flag is used. --tw-suspicious num Set the time warp suspicious value to num seconds. If two records in the wtmp file are farther than this number of seconds apart, there is a problem with the wtmp file (or your machine hasn't been used in a year). If the program notices this problem, time is not assigned to users unless the --timewarps flag is used. -y, --print-year Print year when displaying dates. -z, --print-zeros If a total for any category (save the grand total) is zero, print it. The default is to suppress printing. --debug Print verbose internal information. -V, --version Print the version number of ac to standard output and quit. -h, --help Prints the usage string and default locations of system files to standard output and exits. FILES
wtmp The system wide login record file. See wtmp(5) for further details. AUTHOR
The GNU accounting utilities were written by Noel Cragg <noel@gnu.ai.mit.edu>. The man page was adapted from the accounting texinfo page by Susan Kleinmann <sgk@sgk.tiac.net>. SEE ALSO
login(1), wtmp(5), init(8), sa(8) 2010 August 16 AC(1)
All times are GMT -4. The time now is 05:57 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy