[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Work with awk and text blocks

Posted on 2012-08-14
3
Medium Priority
?
340 Views
Last Modified: 2012-08-16
Hi,
I have big files with a lot of blocks of text like below

START SECTION - Description about block
Here text (can be a lot of lines)
END  SECTION

START SECTION - Description about block
Here text (can be a lot of lines)
END  SECTION

.....etc

I need to forward each block to the separated file with unique file name (can be number of block).

Thanks
0
Comment
Question by:IKeystone
  • 2
3 Comments
 
LVL 26

Accepted Solution

by:
arober11 earned 2000 total points
ID: 38294709
Try:

gawk '/START SECTION/{n++}{print >"out" n ".txt" }' input_file.txt
0
 

Author Comment

by:IKeystone
ID: 38296111
Tested in awk, working. Last question - how to add to the output files process id ?

out(n).$$.txt
0
 
LVL 26

Expert Comment

by:arober11
ID: 38299432
Try:

gawk -v pid=$$  '/START SECTION/{n++}{print >"out" n "." pid ".txt" }' input_file.txt
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses
Course of the Month18 days, 22 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question