Thanks.
I think i would need to give the exact sample of the content.
See below:
My desired output is the Date e.g. 1977-15-07 which is the next 10 characters after (birthday=").
For the above sample line, i should have the below output: ---------- Post updated at 03:29 AM ---------- Previous update was at 12:54 AM ----------
Quote:
Originally Posted by Don Cragun
In your sample, the pattern doesn't matter, and your statement specifying your requirements doesn't match the output you say you want (the double quotes are missing in the output).
To get the output you requested from the input you gave (if I guessed correctly about where the CODE tags should have been), you could try something simple like:
If file contains your sample input, the output produced matches your desired output.
As always, if you're using a Solaris/SunOS system, you need to use /usr/xpg4/bin/awk, /usr/xpg6/bin/awk, or nawk instead of /bin/awk or /usr/bin/awk.
Hi Don, Sorry for the confusion:
I think i would need to give you the exact sample of the file content.
See below:
My desired output is the Date e.g. 1977-15-07 which is the next 10 characters after (birthday=").
For the above sample line, i should have the below output:
Appreciate your help on this. Thanks
Last edited by Scott; 07-25-2013 at 06:24 AM..
Reason: Added code tags
With your new requirements and new sample input, there is still no need to look for birthday=". The following simple awk script produces your new required output with your new exact sample:
What we really need is not an exact sample, but an exact specification of what is allowed in the input this program is supposed to process. But, giving us samples that are not representative of your input just wastes your time and ours.
Last edited by Don Cragun; 07-26-2013 at 12:20 AM..
Reason: Fix typo
>> But, giving us samples that are not representative of your input just wastes your time and ours.
- I Totaly agree with Don. Scripter123 please note it down before posting next time, to have correct sample in first place.
With your new requirements and new sample input, there is still no need to look for birthday=". The following simple awk script produces your new required output with your new exact sample:
What we really need is not an exact sample, but an exact specification of what is allowed in the input this program is supposed to process. But, giving us samples that are not representative of your input just wastes your time and ours.
Hi Don, Thanks, the command works well and apologies on the previous confusion.
I have a follow query on how would i put into a variable the return dates.
print substr($i, 1, 10) - as what i understand, this line will print the return date, how would i put it in a variable?
Hi Don, Thanks, the command works well and apologies on the previous confusion.
I have a follow query on how would i put into a variable the return dates.
print substr($i, 1, 10) - as what i understand, this line will print the return date, how would i put it in a variable?
Yes, the awk command:
prints the up to 10 characters starting with the 1st character from field number i in the current input line.
What kind of variable? What do you want to do with this variable? You're being vague about what you want again!
Is this what you mean?
Is this what you mean?
Both of the above shell scripts produce the same output as my previous awk command, but run slower. For "large" input files, the second one also takes more memory and for "HUGE" input files will eventually run out of memory.
Is this what you mean?
The above shell script will work with any POSIX conforming shell.
Is this what you mean?
The above shell script only works with 1993 and later versions of the Korn shell.
Is this what you mean?
The above shell script only works with bash.
The last three shell scripts above all also produce the same output as my last awk command, but are slower yet. With sufficiently large input files, the last two could run into LINE_MAX, ARG_MAX, shell array size, and/or amount of memory available to the shell limitations.
Obviously there are thousands of other ways to assign output from a utility into variables into variables of various types in various programming languages. If you don't give us details about what you want, we can waste lots of time trying to guess what you want; or we can just ignore future requests for help from you.
Many people post vague questions like yours and the often get results. A few people post questions like:
I am using the WWW shell on XXX hardware running the YYY version of the ZZZ operating system. i have input files with the following input format: description of format
and here is a representative sample of an input file in this format:
input file name:
I want to produce output with the following characteristics: description of output
and here is the output I want to have produced from the input sample above:
output file name:
Here is what I have tried so far:
but it gives me the following errors or fails to produce the output that I want for reasons that I don't understand:
Can you help me correct my code, explain what I'm doing wrong, or tell me where to find an answer for my problem?
People who take the time and effort to start a thread with a post like that almost always get a quick, accurate, and working solution VERY quickly. And future posts from these people are naturally given a much higher priority by the volunteers in The UNIX and Linux Forum who try to help people asking questions.
I had a spot of trouble coming up with a title, hopefully you'll understand once you read my problem... :)
I have the output of an ldapsearch that looks like this:
dn: cn=sam,ou=company,o=com
uidNumber: 7174
gidNumber: 49563
homeDirectory: /home/sam
loginshell: /bin/bash
uid: sam... (2 Replies)
Hi,
I have a folder with multiple (< 33) .log files.
And I have to copy the lines between two patterns from all the .log files to a new file.
(script file with a loop?)
Thanks in advance.
1.log
...
..
xx1> begin
...
..
..
>>> Total: 2 Alarms
..
.. (17 Replies)
Is there a way with aw to print all lines after a string is found
There is a file like this
.......
........
2012/19/11 :11.58 PM some data
lne no date
2012/19/11 :11.59 PM some other data
2012/20/11 :12.00 AM some other data
some line without dates
some more lines without dates... (8 Replies)
i have a file which contains alphanumeric data in every line. what i need is the data after certain pattern. the data after the pattern is not of fixed length so i need the data till the space after the pattern.
Input file:
bfdkasfbdfg khffkf lkdhfhdf pattern (datarequired data not required)... (2 Replies)
Hi all,
I'd like to print the next word after a found pattern.
example text:
word1 word2 word3 word4 pattern word5
pattern word1 word2 word3 word4
word1 word2 pattern word4
basiclly the word after pattern.
Thanks (9 Replies)
Hi,
I have a text file similar to the example below and I want to print the second line every time after the "--------------------------" pattern is found. The pattern is a fixed length of - characters.
Example of input;
1 --------------------------
2
3 39184018234
4 ... (10 Replies)
Hi,
I have a big inventory file that is NOT sorted is any way.
The file is have "tagged" information like the ip address "*IP=" or the name "*NM=" .
How do I get just the ip address or the name and not the whole line?
I have tried to use AWK without any success. I always get the whole line... (8 Replies)
Hi,
My input has much more lines, but few of them are below
pin(IDF) {
direction : input;
drc_pinsigtype : signal;
pin(SELDIV6) {
direction : input;
drc_pinsigtype : ... (3 Replies)
I am trying to do some thing like this ..
In a file , if pattern found insert new pattern at the begining of the line containing the pattern.
example:
in a file I have this.
gtrow0unit1/gctunit_crrownorth_stage5_outnet_feedthru_pin
if i find feedthru_pin want to insert !! at the... (7 Replies)