Sponsored Content
Top Forums Shell Programming and Scripting sed - searching token in certain order Post 302851695 by jcdole on Monday 9th of September 2013 01:29:26 PM
Old 09-09-2013
Quote:
Originally Posted by Don Cragun
That didn't answer the question. Will you accept a solution for this problem that uses awk?
yes of course.

---------- Post updated at 19:29 ---------- Previous update was at 19:21 ----------

Is there something more clean but readable :

Code:
my_function () {
CMD="COUNT=\$(sed -n '/^$1/,\$p'  $2 | sed -n '/^$3/,\$p' | sed '/$5/ q'  | sed -n '1p' | grep -c '$4'   )"
eval $CMD
if [[ $COUNT -gt 0 ]] ; then
    return 0
else
    return 1
fi
}

Code:
asus:~ # my_function  "In the Linux startup process"  "/root/Documents/file_text.txt" "Like init" "manage" "ways"
asus:~ # if [[ $? -eq 0 ]] ; then 
> echo "success"
> else 
> echo "failed"
> fi
success
asus:~ #

Code:
asus:~ # my_function  "In the Linux startup process"  "/root/Documents/file_text.txt" "Like init" "blablabla" "ways"
asus:~ # if [[ $? -eq 0 ]] ; then 
> echo "success"
> else 
> echo "failed"
> fi
failed
asus:~ #

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

using sed and regex to reverse order???

so i have been trying to learn how to manipulate text on my own and have gotten stumped... let's say i have a text file that says (highly simplified): people ordinary How would swap the order of the words.. I know i need to use sed and some kind of back reference but cannot make it... (2 Replies)
Discussion started by: urtherhoda
2 Replies

2. UNIX for Dummies Questions & Answers

Changing the order using sed

I have a text "abc def ghi" and I want to get it as "def abc ghi" I am using this echo "abc def ghi" | sed 's/\(*\)\(*\)/\2\1/' But I am not able to get the output, could anyone help me. Thanks (9 Replies)
Discussion started by: venu_nbk
9 Replies

3. Shell Programming and Scripting

sed searching across lines

hi, i'm making now a bash script, that runs some compiler... i want to take only errors form its output eg: output: bla bla bla ... erros is 1324546 the bla bla bla bla bla bla... ... and i want to get only erros is 1324546 the bla bla bla (11 Replies)
Discussion started by: miechu
11 Replies

4. Shell Programming and Scripting

Reversing file order using SED

Im trying to develop a shell script that will change the content order of the file. For example I have a file that says a b c d I want to change this to be d c b a Im trying to use sed to this by reading the file and then inserting each line at the top #!/usr/bin/ksh ... (3 Replies)
Discussion started by: MBGPS
3 Replies

5. Shell Programming and Scripting

sed or awk to order a file

Hi - I have a file with lots of lines in that I need to order based on the number of commas! e.g the file looks something like :- cn=john,cn=users,cn=uk,dc=dot,dc=com cn=john,cn=users,dc=com cn=users,cn=groups,dc=com cn=john,cn=admins,cn=users,cn=uk,dc=dot,dc=com... (4 Replies)
Discussion started by: sniper57
4 Replies

6. Shell Programming and Scripting

Sed - Pattern Searching

Hi, Please take a look at the below eg. I would like to search for abc() pattern first and then search for (xyz) in the next line. If I can find the pattern, then I should delete the 3 lines. I can only find the pattern and delete but I am unable to find two patterns and delete. Any... (8 Replies)
Discussion started by: sreedevi
8 Replies

7. UNIX for Dummies Questions & Answers

Searching for multiple words on a line in any order issue

Hi again I have figured out how to be able to sort through lines in a file with multiple words in any order and display them using this command: cat file | grep -i $OPTION1 | grep -i $OPTION2 | grep -i $OPTION3 OPTION1 is 2008, OPTION2 is Mar, OPTION 3 is Tue Result: Tue Mar 25... (4 Replies)
Discussion started by: semaj
4 Replies

8. Shell Programming and Scripting

sed - Removing all characters from token to end of line

Hello. The token is any printable characters between 2 " . The token is unknown, but we know that it is between 2 " Tok 1 : "1234x567" Tok 2 : "A3b6+None" Tok 3 : "A3b6!1234=@" The ligne is : Line 1 : "9876xABCDE"Do you have any code fragments or data samples in your post Line 2 : ... (3 Replies)
Discussion started by: jcdole
3 Replies

9. Shell Programming and Scripting

sed string with any order

Hi, i have a strange prob. log file contains ip, protocol, user name, agent . these can be in any order. If log contains the above order able to fetch all details but if details are in diff order not able to fetch all details. using below command. grep -A50 "Entry " "/logs/file.log" \ |grep... (6 Replies)
Discussion started by: Satyak
6 Replies

10. Shell Programming and Scripting

Searching for a token in a file

Hi All, I am new to scripting. I have a requirement where I need to search for token present in array in a file. If the token is found I need to take the first column of that line from the file and append it to token and direct it to a new file. e.g. token file token.txt contains abc... (2 Replies)
Discussion started by: alok2082
2 Replies
ACPITOOL(1)							   User Commands						       ACPITOOL(1)

NAME
acpitool - a Linux ACPI client, allowing you to query or set ACPI values SYNOPSIS
acpitool [ -aAbBcefFhjlmnosStTvVwWz ] DESCRIPTION
acpitool is a Linux ACPI client. It simply reads /proc/acpi or /sys/class entries and presents the output in a meaningfull, human-readable format. It provides a.o. information on battery status, AC adapter presence, thermal reading, etc. This command is most useful on laptops with an ACPI compliant BIOS and a Linux kernel, preferably from the 2.6 series, with ACPI enabled. Acpitool also allows the machine to be put into standby, if your laptop supports it. If your laptop is a Toshiba , it allows you to set the LCD brighness level and toggle the fan on/off. If you have an Asus laptop, it can also set the LCD brightness level, switch the LCD panel on or off, and control the mail led and wireless led. If you have an IBM Thinkpad laptop, it can once again set the LCD brightness level, and also eject the ultrabay device. OPTIONS
-a, --ac_adapter Show AC adapter presence -A Show supported Asus ACPI extensions (LCD brightness level, video out routing DSDT/acpi4asus info) -b Show battery status information, available batteries only. -B, --battery Show detailed battery status information, for all battery entries found. -c, --cpu Show CPU information (type, speed, PM capabilities, throttling states, c-state usage, frequency scaling). -e Show just about everything : more info on the batteries, ACPI version, kernel version, CPU, . . . -f, --fan Show fan status (shows fan info specific to Toshiba or IBM Thinkpad, if applicable). -F x Force the fan on (x=1) or switch back to auto mode (x=0). Works only on Toshiba laptops. The fan is switched off ONLY if it was forced on first, not if it was switched on automatically. Requires write access to /proc/acpi/toshiba/fan -h, --help Show help text. -j Eject Thinkpad ultrabay device. Requires write acces to /proc/acpi/ibm/bay -l x Set LCD brightness level to x, where x is in the range 0..7. Works only on Toshiba and IBM Thinkpad laptops. Requires write access to /proc/acpi/tochiba/lcd or /proc/acpi/ibm/brightness Illegal values for x will result in the value being set to either 0 or 7. -m x Switch the mail led on (x=1) or off (x=0). Works only on Asus laptops. Requires write access to /proc/acpi/asus/mled -n x Switch the wireless led on (x=1) or off (x=0). Works only on Asus laptops. Requires write access to /proc/acpi/asus/wled -o x Switch the LCD panel on (x=1) or off (x=0). Works only on Asus laptops. Requires write access to /proc/acpi/asus/lcd -s, --suspend to memory Put the machine into sleep state S3, if possible. Requires write access to /proc/acpi/sleep (kernel 2.4.x) or /sys/power/state (kernel 2.6.x) -S, --suspend to disk ? Put the machine into sleep state S4, if possible. Requires write access to /proc/acpi/sleep (kernel 2.4.x) or /sys/power/state (kernel 2.6.x) -t, --thermal Show thermal zone(s) information, including trip_points. -T, --Toshiba Show supported Toshiba ACPI extensions, currently being LCD brightness level, video out routing (what display is the video chip sending to) and fan status (on/off, forced or not). -v Show more verbose output when something is not found. Makes sense only when used together with other options. -V, --version Show acpitool version number and release date, then exit. -w Show the wakeup capable devices. (Available since ACPI 20040715, check your version). -W x Enable/disable wakeup capable device x. Run 'acpitool -w' to see valid numbers for x. Requires write access to /proc/acpi/wakeup -z x Set Asus LCD brightness level to x, where x is 0..15. Works only on Asus laptops. Requires write access to /proc/acpi/asus/brn REMARKS
This program absolutely requires a Linux kernel with ACPI support enabled. This program will not work without it. IBM Thinkpad support is part of the Linux kernel since kernel 2.6.10. Don't blame me if acpitool can't suspend your laptop : there are quite some problematic laptops out there. Check the acpi-bugzilla list if you don't believe me ;) Note that some options, like -F, -l , -j, -s, -W and -z, require write access to some of the /proc/acpi entries. This requires acpitool either to be run as root or either administrative measures must be taken, most likely by root, to allow ordinary users to write to these files. Creating a group for ACPI users and setting permissions accordingly comes to mind. Also note that older laptops (< 2000) often simply don't have ACPI support, they usually support APM only. BUGS
Let me know if you think you found one. FILES
/proc/acpi/... /proc/acpi/toshiba /proc/acpi/asus /proc/acpi/ibm /sys/power/state HOMEPAGE
http://freeunix.dyndns.org:8000/site2/acpitool.shtml AUTHOR
This program is written and maintained by David Leemans (davidleemans |at| scarlet |dot| be) and may be freely distributed under the terms of the GNU General Public License. There is ABSOLUTELY NO WARRANTY for this program. AcpiTool 0.5 24 Jul 2008 ACPITOOL(1)
All times are GMT -4. The time now is 08:02 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy