sorting aspecific part of the file

November 23, 2011 at 00:32:50
Specs: Windows XP
hi,

I wanted to sort specific part of the file using shell script.
like my file contains some of the part like:

PostData: P1_Required=P1 Required value&P2_Optional=123456789&P3_Repeating=P3 Repeat - 1st Element!&P3_Repeating=P3 Repeat - 2nd Element!&P3_Repeating=7500

I have to first search for PostData and then to sort this using delimiter $ and then put again into that file.

Can you plz tell me about this?


See More: sorting aspecific part of the file

Report •

#1
November 24, 2011 at 17:34:43
What do you mean? Sort does not use delimiters and in any case $ does not appear in the line you show.

Please explain.


Please come back & tell us if your problem is resolved.


Report •

#2
November 24, 2011 at 22:24:46
Hi Wahine,


This is my old output:
*******************************************************************************
============The Output of HTTP Receiver==========================

Method: POST

RequestURI: /RequestURI_field--GV_Str1_Value

PostData: P2_Optional=123456789&P3_Repeating=P3 Repeat - 1st Element!&P3_Repeating=P3 Repeat - 2nd Element!&P3_Repeating=7500&P1_Required=P1 Required value

Command: /RequestURI_field--GV_Str1_Value

QueryString:

parameters: P1 Required value123456789P3 Repeat - 1st Element!P3 Repeat - 2nd Element!7500


This is my new output:
*******************************************************************************
============The Output of HTTP Receiver==========================

Method: POST

RequestURI: /RequestURI_field--GV_Str1_Value

PostData: P1_Required=P1 Required value&P2_Optional=123456789&P3_Repeating=P3 Repeat - 1st Element!&P3_Repeating=P3 Repeat - 2nd Element!&P3_Repeating=7500

Command: /RequestURI_field--GV_Str1_Value

QueryString:

parameters: P1 Required value123456789P3 Repeat - 1st Element!P3 Repeat - 2nd Element!7500


*****************************************************************************************


Everytime the postdata output is same but not in the same sequence. So I want to sort in such a manner that Parameter-1 comes 1st,Parameter-2 comes 2nd and so on and I don't face this problem again and verify script passes.


Report •

#3
November 26, 2011 at 13:44:51
Please test this script. As you will note if any field in the P3 segments changes the script will fail. Hope this helps.

@echo off>output.txt
cls
setlocal 

more +7 input.txt>%temp%\trial.txt
set /p line=<%temp%\trial.txt

set line=%line:&=$%
set line=%line:!=%
set line=%line:~10%

for /f "tokens=1-5 delims=$" %%1 in ("%line%") do (
    set part=%%1&call :sortit
    set part=%%2&call :sortit
    set part=%%3&call :sortit
    set part=%%4&call :sortit
    set part=%%5&call :sortit
)


for /f "tokens=*" %%1 in (Input.txt) do (
    setlocal enabledelayedexpansion
    set line=%%1
    if not "!line:~0,10!" equ "PostData: " (
       echo %%1>>output.txt
       echo.>>output.txt
       ) else (
         
         setlocal disabledelayedexpansion

         echo PostData: %part1%^&%part2%^&%part3%^!^&%part4%^!^&%part5%>>output.txt
         echo.>>output.txt
  )         
)

type output.txt
exit /b

:sortit
if /i "%part:~0,2%" equ "p1" set part1=%part%
if /i "%part:~0,2%" equ "p2" set part2=%part%
if /i "%part:~0,2%" equ "p3" if /i "%part:~25,3%" equ "1st" set part3=%part%
if /i "%part:~0,2%" equ "p3" if /i "%part:~25,3%" equ "2nd" set part4=%part%
if /i "%part:~0,2%" equ "p3" if /i "%part:~-4%" equ "7500" set part5=%part%


Please come back & tell us if your problem is resolved.


Report •

Related Solutions

#4
November 27, 2011 at 07:03:24
Thanks Wahine!! I will try it and let you know.

Report •

Ask Question