Sponsored Content
Top Forums Shell Programming and Scripting Replace pattern from nth field from a file Post 302950538 by Amit Joshi on Sunday 26th of July 2015 09:46:52 AM
Old 07-26-2015
Replace pattern from nth field from a file

I have posted this again as old post is closed and I am not able to reopen. so please consider this new post

Input File :

Code:
1,A,Completed,06.02_19.36,Jun 30 20:00
2,BBB,Failed,07.04_05.12,Jul 21 19:06
3,CCCCC,New,07.21_03.03,Jul 26 12:57 
4,DDDDD,Pending,,

I wast output file as:
Code:
1,A,Completed,Jun 02 19:36,Jun 30 20:00
2,BBB,Failed,Jul 04 05:12,Jul 21 19:06
3,CCCCC,New,Jul 21 03:03,Jul 26 12:57 
4,DDDDD,Pending,,

Code:
07.21_03.03 is in format of MM.DD_HH.mm

In the above file 4th field is date which is in MM.DD_HH.mm format and I need to convert it to as it to into MON DD HH:mm . Note It can have blank value or space as well.
MM means Month like for 07 means July
DD means day like 21 means 21th day of that month
HH means hour
MIN means minute
MON means Month in 3 letter like for July it should be Jul


Any idea how I can do that in unix shell script with sed or awk or any other command ?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

find pattern and replace another field

HI all I have a problem, I need to replace a field in a file, but only in the lines that have some pattern, example: 100099C01101C00000000059394200701CREoperadora_TX 100099C01201C00000000000099786137OPERADORA_TX2 in the example above I need to change the first field from 1 to 2 only if... (3 Replies)
Discussion started by: sergiioo
3 Replies

2. Shell Programming and Scripting

search pattern and replace x-y characters in nth line after every match

Hi, I am looking for any script which can do the following. have to read a pattern from fileA and copy it to fileB. fileA: ... ... Header ... ... ..p1 ... ... fileB: .... .... Header (3 Replies)
Discussion started by: anilvk
3 Replies

3. Shell Programming and Scripting

how to find the nth field value in delimiter file in unix using awk

Hi All, I wanted to find 200th field value in delimiter file using awk.? awk '{print $200}' inputfile I am getting error message :- awk: The field 200 must be in the range 0 to 199. The source line number is 1. The error context is {print >>> $200 <<< } using... (4 Replies)
Discussion started by: Jairaj
4 Replies

4. Shell Programming and Scripting

Extract a nth field from a comma delimited file

Hi, In my file (which is "," delimited and text qualifier is "), I have to extract a particualr field. file1: 1,"aa,b",4 expected is the 2nd field: aa,b I tried the basic cut -d "," -f 2 file 1, this gave me aa alone instead aa,b. A small hint ot help on this will be very... (5 Replies)
Discussion started by: machomaddy
5 Replies

5. Shell Programming and Scripting

Replace a data in a field if that does not contain a particular pattern

Hi, I have a date/time field in my file. I have to search in all the records and append a timestamp to it, if the timestamp is missing in that field. Is there a possible awk solution for this? Field date format File1 ==== 1|vamu|payer|2007-12-02 02:01:30|bcbs|... (5 Replies)
Discussion started by: machomaddy
5 Replies

6. UNIX for Dummies Questions & Answers

Serach pattern in one field and replace in another

Hi all, I have a TAB separated file like this: sample.rpt: 54 67 common/bin/my/home {{bla bla bla}} {bla bla} Replace Me 89 75 bad/rainy/day/out {{ some bla} } {some bla} Dontreplace Me ...... ...... I wish to do a regexp match on the 3rd... (2 Replies)
Discussion started by: newboy
2 Replies

7. Shell Programming and Scripting

Replace a value of Nth field of nth row

Using Awk, how can I achieve the following? I have set of record numbers, for which, I have to replace the nth field with some values, say spaces. Eg: Set of Records : 4,9,10,55,89,etc I have to change the 8th field of all the above set of records to spaces (10 spaces). Its a delimited... (1 Reply)
Discussion started by: deepakwins
1 Replies

8. Shell Programming and Scripting

Replacing nth field with nth_text for each line in a file

Hi All, I am very new to shell scripting and tried to search this in the forum but no luck. Requirment: I have an input file which is comma separated. I need to replace the value in 4th column with another value. This has to happen for all the lines in the file. Sample data: Input... (2 Replies)
Discussion started by: arunkumarsd
2 Replies

9. Shell Programming and Scripting

Replace pattern from nth field from a file

$ cat /cygdrive/d/Final2.txt 1,A ,Completed, 07.03_23.01 ,Jun 30 20:00 2,BBB,Pending,, 3,CCCCC,Pending,, 4,DDDDD,Pending,, 5,E,Pending,, 6,FFFF,Pending,, 7,G,Pending,, In the above file 4th field is date which is in MM.DD_HH.MIN format and I need to convert it to as it is there in 5th... (1 Reply)
Discussion started by: Amit Joshi
1 Replies

10. Shell Programming and Scripting

Search term in nth field and replace kth column

Hi, I have a text file which looks like this a.txt A,12,Apple,Red B,33,Banana,Yellow C,66,Sky,Blue I need to search for a particular field(s) in particular column(s) and for that matching line need to replace the nth column. Sample scenario 1: Search for 66 in second field and Sky in... (5 Replies)
Discussion started by: wahi80
5 Replies
acctcon(8)						      System Manager's Manual							acctcon(8)

NAME
acctcon1, acctcon2 - Display connect-time accounting summaries SYNOPSIS
acctcon1 [-l file] [-o file] [-p] [-t] acctcon2 FLAGS
Writes line-usage format from the input file (usually /var/adm/wtmp) to file for the accounting period during which the file /var/adm/wtmp is active. The following example shows the ASCII line-usage heading format: TOTAL DURATION: 57 MINUTES LINE MINUTES PERCENT # SESS # ON # OFF pty/ttyp4 37 64 3 3 7 console 26 45 2 2 4 pty/ttyp5 7 11 1 1 3 pty/ttyp6 0 0 0 0 2 TOTALS 69 - 6 6 16 TOTAL DURATION specifies the total number of minutes used for connect sessions during the accounting period during which the /var/adm/wtmp file is active. The columns specify the line name, the number of session minutes used, the percentage of total elapsed time used for the sessions, the number of sessions charged, the number of logins, and the number of logouts. The last line in the line-usage file totals the entries for each column. The line-usage format helps to track line usage and identify bad lines. All hangups, terminations of the login command, and termi- nations of the login shell cause the system to write logout records, so that the number of logouts is often greater than the number of sessions. Writes an overall-record format to file from the input file (usually /var/adm/wtmp) for the accounting period during which the /var/adm/wtmp file is active. The following example shows the overall-record format: from mon day date hh:mm:ss yyyy tz to mon day date hh:mm:ss yyyy tz 2 date changes Number of times the date was changed. 21 acctg off Number of times accounting functions were turned off. 25 run-level S Number of times accounting functions ran in single-user mode. 108 system boot Number of times the system was rebooted. 21 acctg on Number of times accounting functions were turned on. 21 acctcon1 Number of times the acctcon1 command was issued. The first lines specify the date and time stamp, including time zone, of the accounting period start time and end time. Writes the input file (usually /var/adm/wtmp) to the default output device. For example: pty/ttyp1 hoff 616883748 Jul 19 16:35:48 1990 EST pty/ttyp1 hoff 616883825 Jul 19 16:37:05 1990 EST pty/ttyp1 LOGIN 616883833 Jul 19 16:37:13 1990 EST pty/ttyp1 tom 616883837 Jul 19 16:37:17 1990 EST The output columnar format lists the line reference name, the login name, the time in seconds since January 1, 1970, 0 hours, 0 min- utes, 0 seconds, the date, the 24-hour clock time, the year, and the time zone. Uses the last time found in the input file as the ending time for any current processes. This time, rather than current time, is necessary to have reasonable and repeatable values for noncurrent files. The output format is the same as the default output format. The acctcon1 command also maintains a list of ports on which users are logged in. When the acctcon1 command reaches the end of its input, a session record is written for each port that still appears to be active. The acctcon1 command assumes that the input source is the current file and uses current time as the ending time for each session still in progress. DESCRIPTION
The acctcon1 and acctcon2 commands are described separately. acctcon1 The acctcon1 command is invoked by the runacct shell procedure to write a sequence of login and logout records. One record for each con- nect session is written to the specified destination as a sequence of login session records. The /var/adm/wtmp source file should be directed as input to the command. The following example shows the default ASCII columnar output format: 285212673 1192 hoff 85 0 616883748 Jul 19 16:35:48 1990 EST 285212673 1033 tom 10 0 616883837 Jul 19 16:37:17 1990 EST 285212673 0 root 1345 2852 616883855 Jul 19 16:37:35 1990 EST 285212673 1120 jim 0 62 616888058 Jul 19 17:47:38 1990 EST The columns contain the following information: Device address, expressed as a decimal equivalent of the major/minor device address at which the connection was activated. User ID assigned for the connect-session record. Login name under which the session took place. Total num- ber of prime-time seconds for the connect session. Total number of nonprime-time seconds for the connect session. Seconds since the date 0 hours, 0 minutes 0 seconds, 1 January 1970. Month, day of the month, connect-session starting time, year, and time zone. The order of date and time information is locale dependent. The timestamps shown use the default format for date and time values; however, you can define the NLTIME environment variable to change this format. acctcon2 The acctcon2 command is invoked by the runacct shell procedure. It converts a sequence of login session records produced by the acctcon1 command into connect-time total accounting records. These records are often merged with other total accounting records with the acctmerg command to produce a daily report. EXAMPLES
The following example converts login records to a default format login session record report: acctcon1 -t /var/adm/lineuse -o /var/adm/reboots < /var/adm/wtmp > /var/adm/logsess The previous example generates three files. The /var/adm/logsess file lists ending date and 24-hour timestamp records that correspond with the last time that input was obtained with the -t flag. For the accounting period covered by the /var/adm/wtmp file, the /var/adm/lineuse line-usage summary file is generated by the -l flag, and the /var/adm/reboots overall record file is obtained with the -o flag. The following example converts a series of login session records in the /var/adm/logsess file to a total accounting record in the /var/adm/logacct binary file: acctcon2 < /var/adm/logsess > /var/adm/logacct FILES
Specifies command path. Specifies command path. The active login/logout database file. Accounting header files that define formats for writing accounting files. RELATED INFORMATION
Commands: login(1), acct(8), acctmerg(8), fwtmp(8), init(8), wtmpconvert(8). Functions: acct(2). delim off acctcon(8)
All times are GMT -4. The time now is 07:33 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy