Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
hello experts,
i am looking for help on shell scripting. here is my requirement.
I have a file called blackout.txt and content of the file is
Quote:
Oracle Enterprise Manager 10g Release 5 Grid Control 10.2.0.5.0.
Copyright (c) 1996, 2009 Oracle Corporation. All rights reserved.
[orclstg:3872, oracle_emd]
[LISTENER_ORA_ORCLSTG_orclstg, oracle_listener]
[orclstg, host]
[orclstg, oracle_database]
now i need to remove the first three lines and first character and last character in each line. and output should come like this(in one line with one space between each word)
LISTENER_ORA_ORCLSTG_orclstg orclstg orclstg
i was failed to get all three lines in one line. could you please help me.
i have done upto now
Quote:
blackhoney:{oracle}269% sed '1,3d' blackout_txt | awk '{print $1}' | sed 's/.\(.*\)/\1/' | sed 's/\(.*\)./\1/'
LISTENER_BMC_EURSTG_bmeurstg
bmeurstg
BMEURSTG.WORLD
First combining the seds together will make it more efficient.
Next by default awk will use a newline between output records. You can either strip them out later. Setup your awk to concatenate then print the output, or tell awk to use a different record delimiter. I went with the latter.
Thanks for Quick reply.
i am getting following error. please help me where i am doing wrong. i am bit poor in sed and awk command
Quote:
blackhoney:{oracle}: sed -e '1,3d' -e's/.\(.*\)/\1/' -e 's/\(.*\)./\1/' blackout_txt | awk -F, -v ORS=' ' '{print $1}'
awk: syntax error near line 1
awk: bailing out near line 1
awk 'NR > 3 { sub(/^./,"",$1); sub (/.$/,"",$1); printf "%s ", $1 } END { printf "\n" }' blackout.txt
This is a slightly modified version of my previous one, since I'm not sure the Solaris' awk can manage the alternative regular expression (see the pipe in the regexp of the gsub statement). Eventually you can try nawk which is more compatible with GNU awk (that is the linux version).
blackhoney:{oracle}317% awk 'NR > 3 { sub(/^./,"",$1); sub (/.$/,"",$1); printf "%s ", $1 } END { printf "\n" }' blackout_txt
awk: syntax error near line 1
awk: illegal statement near line 1
awk: syntax error near line 1
awk: illegal statement near line 1
i have tired different way, but i am not getting what i am looking for.
Your version of sed may not have the -e option. Try using a semicolon to separate sed commands.
sed '1,3d;s/.\(.*\).$/\1/' blackout_txt
Also use the 'od' or hexdump commands to print out a character by character output of a couple lines of the input file. A non-printable character or different line endings may be tripping you up.
Assuming the file is comma separated for all the data we are looking at, getting rid of character at the end of the line is a waste of time (with awk) as
it is never called. So just:
Assuming the file is comma separated for all the data we are looking at, getting rid of character at the end of the line is a waste of time (with awk) as
it is never called. So just:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.