How to read all data after a specific string from a text file ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to read all data after a specific string from a text file ?
# 8  
Old 12-15-2014
yes the file exist in the path and working fine when tried with Ravinder's command.
# 9  
Old 12-16-2014
@Ravinder,

Your commands were worked fine on windows server If it is installed with any shell application(the machine against which I tested earlier have a shell application installed and thus awk & sed commands were recognized).

But we may have all the machines with that application installed and awk is failed to execute as OS unable to understand this command.

Below is the script working fine w/ machines installed with shell application.
Code:
net users Admin  > c:\groupList.txt

awk '{gsub(/\r/,X,$0);print}' c:\groupList.txt > c:\groupList1.txt

awk '/Local Group Memberships/ {A=1}/Global Group memberships/ {A=0} A{ match($0,/\*.*/);B=substr($0,RSTART,RLENGTH);sub(/\*/,X,B);sub(/[[:space:]]\*/,"\n",B);      print B      }' c:\groupList1.txt > c:\groupListTemp.txt

sed -e 's/ *$//g' c:\groupListTemp.txt > c:\groupListTemp1.txt

for /f "usebackq delims=" %%X in ("c:\groupListTemp1.txt") do (NET LOCALGROUP "%%X" Admin /delete)

Would you mind to assist in changing above awk and sed command to windows equivalent commands.
# 10  
Old 12-16-2014
Hello Manoj,

If you want to avoid all the ugliness of the full path to awk, you need to update your PATH variable to include the path to the directory where awk is located, then you can just type awk to run your programs.

Go to Control Panel->System->Advanced and set your PATH environment variable to include "C:\Program Files (x86)\GnuWin32" at the end (separated by a semi-colon) from previous entry. You can download and run the setup file. This should install your AWK in "C:\Program Files (x86)\GnuWin32". You can run the awk or gawk command from the bin folder or add the folder C:\Program Files (x86)\GnuWin32\bin to your PATH.

NOTE: I have attached the screen shot for same.


Thanks,
R. Singh
How to read all data after a specific string from a text file ?-1w7xjpng
# 11  
Old 12-16-2014
Hi Rajesh,

We can't install any 3rd party application in those servers due to organization standard and security policy. So for few servers awk and sed command will not work. We need to find windows equivalence command may be commands that support batch programming syntax.

I find a command like findstr equivalent to awk in shell but it not getting exact syntax to capture all data in between specified strings(Local Group Memberships and Global Group Memberships)

In the previous reply there is a typo. actually I meant to say we may not but mentioned we may.

"We may not have all the machines with that application installed and awk is failed to execute as OS unable to understand this command. "
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to read data from tab delimited file after a specific position?

Hi Experts, I have a tab deliminated file as below myfile.txt Local Group Memberships *Administrators *Guests I need data in below format starting from 4th position. myfile1.txt Administrators Guests the above one is just an example and there could... (15 Replies)
Discussion started by: Litu1988
15 Replies

2. Windows & DOS: Issues & Discussions

Removing anything from text file except specific string

So, I have a text file that looks like this: 0,0: (168,168,176) #A8A8B0 srgb(168,168,176) 1,0: (168,168,176) #A8A8B0 srgb(168,168,176) 2,0: (166,166,174) #A6A6AE srgb(166,166,174) 3,0: (166,166,174) #A6A6AE srgb(166,166,174) 4,0: (168,168,176) #A8A8B0 srgb(168,168,176) 5,0:... (0 Replies)
Discussion started by: pasc
0 Replies

3. Shell Programming and Scripting

how read specific line in a file and write it in a new text file?

I have list of files in a directory 'dir'. Each file is of type HTML. I need to read each file and get the string which starts with 'http' and write them in a new text file. How can i do this shell scripting? file1.html <head> <url>http://www.google.com</url> </head> file2.html <head>... (6 Replies)
Discussion started by: vel4ever
6 Replies

4. Shell Programming and Scripting

read data from file from a specific duration

Hi, i have log file which keeps on updating almost ever minute but i have certain string in log which will only be displayed between specific time. so i need to search for that string and copy the details starting from that string and stop at certain string below that. example: log file... (2 Replies)
Discussion started by: gpk_newbie
2 Replies

5. Shell Programming and Scripting

Read Write byte range/chunk of data from specific location in file

I am new to Unix so will really appreciate if someone can guide me on this. What I want to do is: Step1: Read binary file - pick first 2 bytes, convert from hex to decimal. Read the next 3 bytes as well. 2 bytes will specify the number of bytes 'n' that I want to read and write... (1 Reply)
Discussion started by: Kbenipel
1 Replies

6. Shell Programming and Scripting

Reading data from a specific line in a text file

Hello, I have a problem which is giving me headache for days, can some please help. Please see code and text fiel below. Please see text in red for the problem I am facing # Program gets an input x from user while read line ; do echo... (4 Replies)
Discussion started by: jermaine4ever
4 Replies

7. Shell Programming and Scripting

Reading data from a specific line in a text file

hello, I have got the following problem that I am hoping someone can help with please. 1. I have got the following text file (below) , the columns data are 'Test Day', 'Board', 'Betting Number'. TEXT FILE ============================================ 1 3 02-01-27-28-29-30 0 1... (1 Reply)
Discussion started by: jermaine4ever
1 Replies

8. Shell Programming and Scripting

read space filled file and replace text at specific position

Hi I have a spaced filled file having records like below: What I want is to read line having RT3 at position 17-19 then go to position 2651 check the 18 characters (might be space filled till 18 characters). This position should have a... (6 Replies)
Discussion started by: COD
6 Replies

9. Shell Programming and Scripting

read specific text from a log file

Hi guys I need to retrieve the values in BOLD that I have mentioned in the below log file. I want to store those values in a variable, preferably the same name as the column name in the log file. if you paste the below mentioned log file in a notepad and remove the word wrap.. u will get a... (4 Replies)
Discussion started by: ragha81
4 Replies
Login or Register to Ask a Question