2013年8月28日星期三

How to use shell + awk positioning


As shown above, seeking direction, no source code! Not to hand the party!

------ Solution ------------------------------------ --------


[tmp] $ cat urfile
# network module
insmod / 8190.ko
insmod / 8191.ko
insmod / 8192.ko

# rtk8723au usb ti module
insmod / 8193.ko
[tmp] $ awk-v RS = '{if ($ 0 ~ / # network module /) $ 0 = $ 0 "\ n \ tHello world!"; print } 'urfile
# network module
insmod / 8190.ko
insmod / 8191.ko
insmod / 8192.ko
Hello world!
# rtk8723au usb ti module
insmod / 8193.ko
------ For reference only ------------ ---------------------------
  The reply deleted by an administrator at 2013-08-17 10:00:15

------ For reference only ---------------------------------- -----
[root @ tmp] # cat urfile
# network module
insmod / 8190.ko
insmod / 8191.ko
insmod / 8192.ko

# rtk8723au usb ti module
insmod / 8193.ko

[root @ tmp] # sed '/ insmod. * 8192.ko / s / $ / \ n \ tHello world! /' urfile
# network module
insmod / 8190.ko
insmod / 8191.ko
insmod / 8192.ko
Hello world!

# rtk8723au usb ti module
insmod / 8193.ko

------ For reference only ---------------------------------- -----
[root @ tmp] # cat urfile
# network module
insmod / 8190.ko
insmod / 8191.ko
insmod / 8192.ko

# rtk8723au usb ti module
insmod / 8193.ko

[root @ tmp] # awk '{if ($ 0 ~ / insmod. * 8192.ko /) $ 0 = $ 0 "\ n \ tHello world!"; print}' urfile
# network module
insmod / 8190.ko
insmod / 8191.ko
insmod / 8192.ko
Hello world!

# rtk8723au usb ti module
insmod / 8193.ko
------ For reference only ------------ ---------------------------


Moderators adults, you this is not common now! chinaunix
I saw this:
sed '/#network module/{:b;N;/\n#/!bb;s/\([^ ]\+\)\s\+\(\n#.*\)/\1\n\thelloworld\n\2/}' file

Some feel generic.
------ For reference only -------------------------------------- -
mainly based on paragraphs, if judged according to the content, it becomes extremely non-generic! If the content is the same, and there is no way to use it.
------ For reference only -------------------------------------- -

I was this based on your needs first navigate to 8192cu.ko write
If you want general, it is best to ask questions in the attic when clearly described.

If red box contents fixed, so can it?
sed '/#rtk8723au usb ti module/ s/^/\tHello world\n&/' urfile

------ For reference only ----------------------------------- ----
or am I required to say clear, sin a sin! Asked after finishing a good time requirements.

mainly use awk and sed to determine paragraphs. What is the beginning of the next segment is uncertain! At the beginning of this paragraph is for certain!

没有评论:

发表评论